UNPKG

studiocms

Version:

Astro Native CMS for AstroDB. Built from the ground up by the Astro community.

88 lines (87 loc) 4.61 kB
import type { AstroIntegrationLogger } from 'astro'; import type { RobotsConfig } from './schema.js'; /** * Validates the given host string against a specific pattern and logs errors if the validation fails. * * @param host - The host string to be validated. * @param logger - The logger instance used to log error messages. * @throws Will throw an error if the host is not a string or if it does not match the required pattern. */ export declare function validateHost(host: string, logger: AstroIntegrationLogger): void; /** * Generates the host content for the robots.txt file based on the provided configuration. * * @param {RobotsConfig} config - The configuration object for generating the host content. * @param {AstroIntegrationLogger} logger - The logger instance for logging validation messages. * @returns {string} The generated host content for the robots.txt file. * * @remarks * - If `config.host` is `true`, the default host is used. * - If `config.host` is `false`, the host is not specified. * - If `config.host` is a number, it is validated and used. * - If `config.host` is a string and not 'localhost', it is validated and used. */ export declare function generateHostContent(config: RobotsConfig, logger: AstroIntegrationLogger): string; /** * Validates the given URL to ensure it is a valid sitemap file URL. * * The URL must start with "http" or "https" and end with one of the following extensions: * - .xml * - .txt * - .html * - .xml.gz * - .txt.gz * - .json * - .xhtml * * If the URL is invalid, an error message is logged and an exception is thrown. * * @param url - The URL to validate. * @param logger - The logger instance to use for logging error messages. * @throws Will throw an error if the URL is invalid or not a valid sitemap file. */ export declare function validateUrl(url: string, logger: AstroIntegrationLogger): void; /** * Generates the content for the sitemap based on the provided configuration. * * @param {RobotsConfig} config - The configuration object for the robots.txt file. * @param {string} siteHref - The base URL of the site. * @param {AstroIntegrationLogger} logger - The logger instance for logging messages. * @returns {string} The generated sitemap content. * @throws Will throw an error if the sitemap configuration is an invalid number. */ export declare function generateSitemapContent(config: RobotsConfig, siteHref: string, logger: AstroIntegrationLogger): string; /** * Throws a message with a specific type and logs it using the provided logger. * * @param msg - The message to be logged and thrown. * @param type - The type of the message. It can be a boolean, 'warn', 'error', or 'info'. * - 'warn': Logs a warning message. * - 'error': Logs a failure message and throws an error with the message. * - true: Logs a failure message and throws an error with the message and a reference link to Google's robots.txt rules. * - default: Logs a failure message and throws an error with the message and a reference link to Yandex's robots.txt rules. * @param logger - The logger instance used to log the messages. */ export declare function throwMsg(msg: string, type: boolean | 'warn' | 'error' | 'info', logger: AstroIntegrationLogger): void; /** * Generates the content for the robots.txt file based on the provided configuration. * * @param {RobotsConfig} config - The configuration object for generating the robots.txt content. * @param {string} siteMapHref - The URL of the sitemap. * @param {AstroIntegrationLogger} logger - The logger instance for logging messages. * @returns {string} The generated content for the robots.txt file. * * @throws Will throw an error if any policy is missing a required userAgent, * if both allow and disallow entries are missing or empty, * if crawlDelay is not a number or is out of the allowed range (0.1 to 60 seconds). */ export declare function generateContent(config: RobotsConfig, siteMapHref: string, logger: AstroIntegrationLogger): string; /** * Prints information about the generation of the 'robots.txt' file. * * @param fileSize - The size of the generated 'robots.txt' file in KB. * @param executionTime - The time taken to generate the 'robots.txt' file in milliseconds. * @param logger - The logger instance used to log information. * @param destDir - The destination directory where the 'robots.txt' file is created. */ export declare function printInfo(fileSize: number, executionTime: number, logger: AstroIntegrationLogger, destDir: string): void;