mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 22:17:00 +02:00
feat(preset-classic): exclude debug plugin routes from sitemap (#7122)
This commit is contained in:
parent
bfbc78e52a
commit
0963bff5e7
3 changed files with 22 additions and 10 deletions
|
@ -9,6 +9,8 @@ import type {LoadContext, Plugin} from '@docusaurus/types';
|
||||||
import {docuHash, normalizeUrl, posixPath} from '@docusaurus/utils';
|
import {docuHash, normalizeUrl, posixPath} from '@docusaurus/utils';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
|
export const routeBasePath = '__docusaurus/debug';
|
||||||
|
|
||||||
export default function pluginDebug({
|
export default function pluginDebug({
|
||||||
siteConfig: {baseUrl},
|
siteConfig: {baseUrl},
|
||||||
generatedFilesDir,
|
generatedFilesDir,
|
||||||
|
@ -40,37 +42,37 @@ export default function pluginDebug({
|
||||||
|
|
||||||
// Home is config (duplicate for now)
|
// Home is config (duplicate for now)
|
||||||
addRoute({
|
addRoute({
|
||||||
path: normalizeUrl([baseUrl, '__docusaurus/debug']),
|
path: normalizeUrl([baseUrl, routeBasePath]),
|
||||||
component: '@theme/DebugConfig',
|
component: '@theme/DebugConfig',
|
||||||
exact: true,
|
exact: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
addRoute({
|
addRoute({
|
||||||
path: normalizeUrl([baseUrl, '__docusaurus/debug/config']),
|
path: normalizeUrl([baseUrl, routeBasePath, 'config']),
|
||||||
component: '@theme/DebugConfig',
|
component: '@theme/DebugConfig',
|
||||||
exact: true,
|
exact: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
addRoute({
|
addRoute({
|
||||||
path: normalizeUrl([baseUrl, '__docusaurus/debug/metadata']),
|
path: normalizeUrl([baseUrl, routeBasePath, 'metadata']),
|
||||||
component: '@theme/DebugSiteMetadata',
|
component: '@theme/DebugSiteMetadata',
|
||||||
exact: true,
|
exact: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
addRoute({
|
addRoute({
|
||||||
path: normalizeUrl([baseUrl, '__docusaurus/debug/registry']),
|
path: normalizeUrl([baseUrl, routeBasePath, 'registry']),
|
||||||
component: '@theme/DebugRegistry',
|
component: '@theme/DebugRegistry',
|
||||||
exact: true,
|
exact: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
addRoute({
|
addRoute({
|
||||||
path: normalizeUrl([baseUrl, '__docusaurus/debug/routes']),
|
path: normalizeUrl([baseUrl, routeBasePath, 'routes']),
|
||||||
component: '@theme/DebugRoutes',
|
component: '@theme/DebugRoutes',
|
||||||
exact: true,
|
exact: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
addRoute({
|
addRoute({
|
||||||
path: normalizeUrl([baseUrl, '__docusaurus/debug/content']),
|
path: normalizeUrl([baseUrl, routeBasePath, 'content']),
|
||||||
component: '@theme/DebugContent',
|
component: '@theme/DebugContent',
|
||||||
exact: true,
|
exact: true,
|
||||||
modules: {
|
modules: {
|
||||||
|
@ -79,7 +81,7 @@ export default function pluginDebug({
|
||||||
});
|
});
|
||||||
|
|
||||||
addRoute({
|
addRoute({
|
||||||
path: normalizeUrl([baseUrl, '__docusaurus/debug/globalData']),
|
path: normalizeUrl([baseUrl, routeBasePath, 'globalData']),
|
||||||
component: '@theme/DebugGlobalData',
|
component: '@theme/DebugGlobalData',
|
||||||
exact: true,
|
exact: true,
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
|
|
||||||
/// <reference types="@docusaurus/module-type-aliases" />
|
/// <reference types="@docusaurus/module-type-aliases" />
|
||||||
|
|
||||||
|
declare module '@docusaurus/plugin-debug' {
|
||||||
|
export const routeBasePath: string;
|
||||||
|
}
|
||||||
|
|
||||||
declare module '@theme/DebugConfig' {
|
declare module '@theme/DebugConfig' {
|
||||||
export default function DebugMetadata(): JSX.Element;
|
export default function DebugMetadata(): JSX.Element;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {routeBasePath as debugPluginRouteBasePath} from '@docusaurus/plugin-debug';
|
||||||
import type {
|
import type {
|
||||||
Preset,
|
Preset,
|
||||||
LoadContext,
|
LoadContext,
|
||||||
|
@ -28,7 +29,7 @@ export default function preset(
|
||||||
opts: Options = {},
|
opts: Options = {},
|
||||||
): Preset {
|
): Preset {
|
||||||
const {siteConfig} = context;
|
const {siteConfig} = context;
|
||||||
const {themeConfig} = siteConfig;
|
const {themeConfig, baseUrl} = siteConfig;
|
||||||
const {algolia} = themeConfig as Partial<ThemeConfig>;
|
const {algolia} = themeConfig as Partial<ThemeConfig>;
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
const {
|
const {
|
||||||
|
@ -36,12 +37,13 @@ export default function preset(
|
||||||
docs,
|
docs,
|
||||||
blog,
|
blog,
|
||||||
pages,
|
pages,
|
||||||
sitemap,
|
sitemap = {},
|
||||||
theme,
|
theme,
|
||||||
googleAnalytics,
|
googleAnalytics,
|
||||||
gtag,
|
gtag,
|
||||||
...rest
|
...rest
|
||||||
} = opts;
|
} = opts;
|
||||||
|
const isDebugEnabled = debug || (debug === undefined && !isProd);
|
||||||
|
|
||||||
const themes: PluginConfig[] = [];
|
const themes: PluginConfig[] = [];
|
||||||
themes.push(makePluginConfig('@docusaurus/theme-classic', theme));
|
themes.push(makePluginConfig('@docusaurus/theme-classic', theme));
|
||||||
|
@ -74,13 +76,17 @@ export default function preset(
|
||||||
makePluginConfig('@docusaurus/plugin-google-analytics', googleAnalytics),
|
makePluginConfig('@docusaurus/plugin-google-analytics', googleAnalytics),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (debug || (debug === undefined && !isProd)) {
|
if (isDebugEnabled) {
|
||||||
plugins.push(require.resolve('@docusaurus/plugin-debug'));
|
plugins.push(require.resolve('@docusaurus/plugin-debug'));
|
||||||
}
|
}
|
||||||
if (gtag) {
|
if (gtag) {
|
||||||
plugins.push(makePluginConfig('@docusaurus/plugin-google-gtag', gtag));
|
plugins.push(makePluginConfig('@docusaurus/plugin-google-gtag', gtag));
|
||||||
}
|
}
|
||||||
if (isProd && sitemap !== false) {
|
if (isProd && sitemap !== false) {
|
||||||
|
if (isDebugEnabled) {
|
||||||
|
sitemap.ignorePatterns ??= [];
|
||||||
|
sitemap.ignorePatterns.push(`${baseUrl}${debugPluginRouteBasePath}/**`);
|
||||||
|
}
|
||||||
plugins.push(makePluginConfig('@docusaurus/plugin-sitemap', sitemap));
|
plugins.push(makePluginConfig('@docusaurus/plugin-sitemap', sitemap));
|
||||||
}
|
}
|
||||||
if (Object.keys(rest).length > 0) {
|
if (Object.keys(rest).length > 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue