1 | /// <reference types="node" />
|
2 | import { WriteStream } from 'fs';
|
3 | import { Transform, TransformOptions, TransformCallback } from 'stream';
|
4 | import { IndexItem, SitemapItemLoose, ErrorLevel } from './types';
|
5 | import { SitemapStream } from './sitemap-stream';
|
6 | export declare enum IndexTagNames {
|
7 | sitemap = "sitemap",
|
8 | loc = "loc",
|
9 | lastmod = "lastmod"
|
10 | }
|
11 | /**
|
12 | * Options for the SitemapIndexStream
|
13 | */
|
14 | export interface SitemapIndexStreamOptions extends TransformOptions {
|
15 | /**
|
16 | * Whether to output the lastmod date only (no time)
|
17 | *
|
18 | * @default false
|
19 | */
|
20 | lastmodDateOnly?: boolean;
|
21 | /**
|
22 | * How to handle errors in passed in urls
|
23 | *
|
24 | * @default ErrorLevel.WARN
|
25 | */
|
26 | level?: ErrorLevel;
|
27 | /**
|
28 | * URL to an XSL stylesheet to include in the XML
|
29 | */
|
30 | xslUrl?: string;
|
31 | }
|
32 | /**
|
33 | * `SitemapIndexStream` is a Transform stream that takes `IndexItem`s or sitemap URL strings and outputs a stream of sitemap index XML.
|
34 | *
|
35 | * It automatically handles the XML declaration and the opening and closing tags for the sitemap index.
|
36 | *
|
37 | * ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
|
38 | * before `finish` will be emitted. Failure to read the stream will result in hangs.
|
39 | *
|
40 | * @extends {Transform}
|
41 | */
|
42 | export declare class SitemapIndexStream extends Transform {
|
43 | lastmodDateOnly: boolean;
|
44 | level: ErrorLevel;
|
45 | xslUrl?: string;
|
46 | private hasHeadOutput;
|
47 | /**
|
48 | * `SitemapIndexStream` is a Transform stream that takes `IndexItem`s or sitemap URL strings and outputs a stream of sitemap index XML.
|
49 | *
|
50 | * It automatically handles the XML declaration and the opening and closing tags for the sitemap index.
|
51 | *
|
52 | * ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
|
53 | * before `finish` will be emitted. Failure to read the stream will result in hangs.
|
54 | *
|
55 | * @param {SitemapIndexStreamOptions} [opts=defaultStreamOpts] - Stream options.
|
56 | */
|
57 | constructor(opts?: SitemapIndexStreamOptions);
|
58 | private writeHeadOutput;
|
59 | _transform(item: IndexItem | string, encoding: string, callback: TransformCallback): void;
|
60 | _flush(cb: TransformCallback): void;
|
61 | }
|
62 | declare type getSitemapStreamFunc = (i: number) => [IndexItem | string, SitemapStream, WriteStream];
|
63 | /**
|
64 | * Options for the SitemapAndIndexStream
|
65 | *
|
66 | * @extends {SitemapIndexStreamOptions}
|
67 | */
|
68 | export interface SitemapAndIndexStreamOptions extends SitemapIndexStreamOptions {
|
69 | /**
|
70 | * Max number of items in each sitemap XML file.
|
71 | *
|
72 | * When the limit is reached the current sitemap file will be closed,
|
73 | * a wait for `finish` on the target write stream will happen,
|
74 | * and a new sitemap file will be created.
|
75 | *
|
76 | * Range: 1 - 50,000
|
77 | *
|
78 | * @default 45000
|
79 | */
|
80 | limit?: number;
|
81 | /**
|
82 | * Callback for SitemapIndexAndStream that creates a new sitemap stream for a given sitemap index.
|
83 | *
|
84 | * Called when a new sitemap file is needed.
|
85 | *
|
86 | * The write stream is the destination where the sitemap was piped.
|
87 | * SitemapAndIndexStream will wait for the `finish` event on each sitemap's
|
88 | * write stream before moving on to the next sitemap. This ensures that the
|
89 | * contents of the write stream will be fully written before being used
|
90 | * by any following operations (e.g. uploading, reading contents for unit tests).
|
91 | *
|
92 | * @param i - The index of the sitemap file
|
93 | * @returns A tuple containing the index item to be written into the sitemap index, the sitemap stream, and the write stream for the sitemap pipe destination
|
94 | */
|
95 | getSitemapStream: getSitemapStreamFunc;
|
96 | }
|
97 | /**
|
98 | * `SitemapAndIndexStream` is a Transform stream that takes in sitemap items,
|
99 | * writes them to sitemap files, adds the sitemap files to a sitemap index,
|
100 | * and creates new sitemap files when the count limit is reached.
|
101 | *
|
102 | * It waits for the target stream of the current sitemap file to finish before
|
103 | * moving on to the next if the target stream is returned by the `getSitemapStream`
|
104 | * callback in the 3rd position of the tuple.
|
105 | *
|
106 | * ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
|
107 | * before `finish` will be emitted. Failure to read the stream will result in hangs.
|
108 | *
|
109 | * @extends {SitemapIndexStream}
|
110 | */
|
111 | export declare class SitemapAndIndexStream extends SitemapIndexStream {
|
112 | private itemsWritten;
|
113 | private getSitemapStream;
|
114 | private currentSitemap?;
|
115 | private limit;
|
116 | private currentSitemapPipeline?;
|
117 | /**
|
118 | * `SitemapAndIndexStream` is a Transform stream that takes in sitemap items,
|
119 | * writes them to sitemap files, adds the sitemap files to a sitemap index,
|
120 | * and creates new sitemap files when the count limit is reached.
|
121 | *
|
122 | * It waits for the target stream of the current sitemap file to finish before
|
123 | * moving on to the next if the target stream is returned by the `getSitemapStream`
|
124 | * callback in the 3rd position of the tuple.
|
125 | *
|
126 | * ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
|
127 | * before `finish` will be emitted. Failure to read the stream will result in hangs.
|
128 | *
|
129 | * @param {SitemapAndIndexStreamOptions} opts - Stream options.
|
130 | */
|
131 | constructor(opts: SitemapAndIndexStreamOptions);
|
132 | _transform(item: SitemapItemLoose, encoding: string, callback: TransformCallback): void;
|
133 | private writeItem;
|
134 | /**
|
135 | * Called when the stream is finished.
|
136 | * If there is a current sitemap, we wait for it to finish before calling the callback.
|
137 | *
|
138 | * @param cb
|
139 | */
|
140 | _flush(cb: TransformCallback): void;
|
141 | private createSitemap;
|
142 | }
|
143 | export {};
|