UNPKG

sitemap

Version:
87 lines (86 loc) • 3.96 kB
/*! * Sitemap * Copyright(c) 2011 Eugene Kalinin * MIT Licensed */ import { type WriteStream } from 'node:fs'; import { Readable, type ReadableOptions, type TransformOptions, type Writable } from 'node:stream'; import type { SitemapItem, SitemapItemLoose, CharDataBuffer, CharDataHandlers, SitemapFileOptions } from './types.js'; /** * Per ADR 0001, CDATA sections are ordinary character data: wire both the SAX * `text` and `cdata` events to `append`. Character data is joined, trimmed and * handed to `onText` once at the next tag boundary, attributed to the innermost * open element (which is not the last opened tag once a child has closed). * An element whose character data exceeds LIMITS.MAX_PARSER_CHAR_DATA_LENGTH is * dropped and reported through `onOverflow` to bound memory use. */ export declare function createCharDataBuffer({ onText, onOverflow, }: CharDataHandlers): CharDataBuffer; /** * Combines multiple streams into one * @param streams the streams to combine */ export declare function mergeStreams(streams: Readable[], options?: TransformOptions): Readable; export interface ReadlineStreamOptions extends ReadableOptions { input: Readable; } /** * Wraps node's ReadLine in a stream */ export declare class ReadlineStream extends Readable { private _source; constructor(options: ReadlineStreamOptions); _read(size: number): void; } /** * Takes a stream likely from fs.createReadStream('./path') and returns a stream * of sitemap items * @param stream a stream of line separated urls. * @param opts.isJSON is the stream line separated JSON. leave undefined to guess */ export declare function lineSeparatedURLsToSitemapOptions(stream: Readable, { isJSON }?: { isJSON?: boolean; }): Readable; /** * Returns `err` if it is an Error, or wraps it in one, for passing a caught * value to a stream callback */ export declare function toError(err: unknown): Error; /** * Converts the passed in sitemap entry into one capable of being consumed by SitemapItem * @param {string | SitemapItemLoose} elem the string or object to be converted * @param {string} hostname * @returns SitemapItemOptions a strict sitemap item option */ export declare function normalizeURL(elem: string | SitemapItemLoose, hostname?: string, lastmodDateOnly?: boolean): SitemapItem; /** * Connects a sitemap to the stream that writes its file, through gzip when * `gzip` is true. Uses `pipeline()`, which destroys every stream when one * fails, so a gzip failure also fails `writeStream`, which * `SitemapAndIndexStream` watches. * * @param onError - Called with the error if the pipeline fails. */ export declare function pipeSitemapToFile(sitemap: Readable, writeStream: Writable, gzip: boolean, onError: (err: Error) => void): void; /** * Walks up from `fromDir` to the filesystem root and returns the first path * where `relativePath` exists, or undefined if there is none. * * Used to find files that ship with the package (`package.json`, the schema) * from a module's own directory, whatever the build's output layout. */ export declare function findUp(relativePath: string, fromDir: string): string | undefined; /** * Opens sitemap number `index` as a file, for a `SitemapAndIndexStream` * `getSitemapStream` callback: names it `sitemap-N.xml` (`.xml.gz` when * gzipped), builds its URL, checks the URL before creating the file so a URL * the index would reject leaves no empty file behind, and pipes `sitemap` into * it. * * @returns the `[url, sitemap, writeStream]` tuple `getSitemapStream` returns */ export declare function openSitemapFile<S extends Readable>(index: number, sitemap: S, { destinationDir, gzip, toURL, urlParamName, onError }: SitemapFileOptions): [string, S, WriteStream]; /** * Message text of a caught value, for embedding in a wrapping error's message. * @param err - anything caught by a `catch` clause */ export declare function errorMessage(err: unknown): string;