This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { DocusaurusConfig } from '@docusaurus/types';
import type { HelmetServerState } from 'react-helmet-async';
import type { PluginOptions } from './options';
export default function createSitemap(siteConfig: DocusaurusConfig, routesPaths: string[], head: {
[location: string]: HelmetServerState;
}, options: PluginOptions): Promise<string | null>;

View File

@@ -0,0 +1,56 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const sitemap_1 = require("sitemap");
const utils_common_1 = require("@docusaurus/utils-common");
const utils_1 = require("@docusaurus/utils");
function isNoIndexMetaRoute({ head, route, }) {
const isNoIndexMetaTag = ({ name, content, }) => {
if (!name || !content) {
return false;
}
return (
// meta name is not case-sensitive
name.toLowerCase() === 'robots' &&
// Robots directives are not case-sensitive
content.toLowerCase().includes('noindex'));
};
// https://github.com/staylor/react-helmet-async/pull/167
const meta = head[route]?.meta.toComponent();
return meta?.some((tag) => isNoIndexMetaTag({ name: tag.props.name, content: tag.props.content }));
}
async function createSitemap(siteConfig, routesPaths, head, options) {
const { url: hostname } = siteConfig;
if (!hostname) {
throw new Error('URL in docusaurus.config.js cannot be empty/undefined.');
}
const { changefreq, priority, ignorePatterns } = options;
const ignoreMatcher = (0, utils_1.createMatcher)(ignorePatterns);
function isRouteExcluded(route) {
return (route.endsWith('404.html') ||
ignoreMatcher(route) ||
isNoIndexMetaRoute({ head, route }));
}
const includedRoutes = routesPaths.filter((route) => !isRouteExcluded(route));
if (includedRoutes.length === 0) {
return null;
}
const sitemapStream = new sitemap_1.SitemapStream({ hostname });
includedRoutes.forEach((routePath) => sitemapStream.write({
url: (0, utils_common_1.applyTrailingSlash)(routePath, {
trailingSlash: siteConfig.trailingSlash,
baseUrl: siteConfig.baseUrl,
}),
changefreq,
priority,
}));
sitemapStream.end();
const generatedSitemap = (await (0, sitemap_1.streamToPromise)(sitemapStream)).toString();
return generatedSitemap;
}
exports.default = createSitemap;

11
node_modules/@docusaurus/plugin-sitemap/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { PluginOptions, Options } from './options';
import type { LoadContext, Plugin } from '@docusaurus/types';
export default function pluginSitemap(context: LoadContext, options: PluginOptions): Plugin<void>;
export { validateOptions } from './options';
export type { PluginOptions, Options };

41
node_modules/@docusaurus/plugin-sitemap/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,41 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateOptions = void 0;
const tslib_1 = require("tslib");
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
const path_1 = tslib_1.__importDefault(require("path"));
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
const createSitemap_1 = tslib_1.__importDefault(require("./createSitemap"));
function pluginSitemap(context, options) {
return {
name: 'docusaurus-plugin-sitemap',
async postBuild({ siteConfig, routesPaths, outDir, head }) {
if (siteConfig.noIndex) {
return;
}
// Generate sitemap.
const generatedSitemap = await (0, createSitemap_1.default)(siteConfig, routesPaths, head, options);
if (!generatedSitemap) {
return;
}
// Write sitemap file.
const sitemapPath = path_1.default.join(outDir, options.filename);
try {
await fs_extra_1.default.outputFile(sitemapPath, generatedSitemap);
}
catch (err) {
logger_1.default.error('Writing sitemap failed.');
throw err;
}
},
};
}
exports.default = pluginSitemap;
var options_1 = require("./options");
Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { EnumChangefreq } from 'sitemap';
import type { OptionValidationContext } from '@docusaurus/types';
export type PluginOptions = {
/** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */
changefreq: EnumChangefreq;
/** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */
priority: number;
/**
* A list of glob patterns; matching route paths will be filtered from the
* sitemap. Note that you may need to include the base URL in here.
*/
ignorePatterns: string[];
/**
* The path to the created sitemap file, relative to the output directory.
* Useful if you have two plugin instances outputting two files.
*/
filename: string;
};
export type Options = Partial<PluginOptions>;
export declare const DEFAULT_OPTIONS: PluginOptions;
export declare function validateOptions({ validate, options, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;

39
node_modules/@docusaurus/plugin-sitemap/lib/options.js generated vendored Normal file
View File

@@ -0,0 +1,39 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateOptions = exports.DEFAULT_OPTIONS = void 0;
const utils_validation_1 = require("@docusaurus/utils-validation");
const sitemap_1 = require("sitemap");
exports.DEFAULT_OPTIONS = {
changefreq: sitemap_1.EnumChangefreq.WEEKLY,
priority: 0.5,
ignorePatterns: [],
filename: 'sitemap.xml',
};
const PluginOptionSchema = utils_validation_1.Joi.object({
// @ts-expect-error: forbidden
cacheTime: utils_validation_1.Joi.forbidden().messages({
'any.unknown': 'Option `cacheTime` in sitemap config is deprecated. Please remove it.',
}),
changefreq: utils_validation_1.Joi.string()
.valid(...Object.values(sitemap_1.EnumChangefreq))
.default(exports.DEFAULT_OPTIONS.changefreq),
priority: utils_validation_1.Joi.number().min(0).max(1).default(exports.DEFAULT_OPTIONS.priority),
ignorePatterns: utils_validation_1.Joi.array()
.items(utils_validation_1.Joi.string())
.default(exports.DEFAULT_OPTIONS.ignorePatterns),
trailingSlash: utils_validation_1.Joi.forbidden().messages({
'any.unknown': 'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.',
}),
filename: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.filename),
});
function validateOptions({ validate, options, }) {
const validatedOptions = validate(PluginOptionSchema, options);
return validatedOptions;
}
exports.validateOptions = validateOptions;