diff --git a/packages/docusaurus-plugin-content-blog/src/index.ts b/packages/docusaurus-plugin-content-blog/src/index.ts index 2d1ad57626..c21cfe4a85 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.ts +++ b/packages/docusaurus-plugin-content-blog/src/index.ts @@ -242,25 +242,26 @@ export default async function pluginContentBlog( ? blogPosts : blogPosts.slice(0, options.blogSidebarCount); - const archiveUrl = normalizeUrl([ - baseUrl, - routeBasePath, - archiveBasePath, - ]); - - // creates a blog archive route - const archiveProp = await createData( - `${docuHash(archiveUrl)}.json`, - JSON.stringify({blogPosts}, null, 2), - ); - addRoute({ - path: archiveUrl, - component: '@theme/BlogArchivePage', - exact: true, - modules: { - archive: aliasedSource(archiveProp), - }, - }); + if (archiveBasePath) { + const archiveUrl = normalizeUrl([ + baseUrl, + routeBasePath, + archiveBasePath, + ]); + // creates a blog archive route + const archiveProp = await createData( + `${docuHash(archiveUrl)}.json`, + JSON.stringify({blogPosts}, null, 2), + ); + addRoute({ + path: archiveUrl, + component: '@theme/BlogArchivePage', + exact: true, + modules: { + archive: aliasedSource(archiveProp), + }, + }); + } // This prop is useful to provide the blog list sidebar const sidebarProp = await createData( diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index e141e2dd9f..0ef6cf9704 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -112,7 +112,7 @@ declare module '@docusaurus/plugin-content-blog' { path: string; routeBasePath: string; tagsBasePath: string; - archiveBasePath: string; + archiveBasePath: string | null; include: string[]; exclude: string[]; postsPerPage: number | 'ALL'; diff --git a/packages/docusaurus-plugin-content-blog/src/pluginOptionSchema.ts b/packages/docusaurus-plugin-content-blog/src/pluginOptionSchema.ts index 4fcf2064ba..d72d9bea6e 100644 --- a/packages/docusaurus-plugin-content-blog/src/pluginOptionSchema.ts +++ b/packages/docusaurus-plugin-content-blog/src/pluginOptionSchema.ts @@ -47,7 +47,9 @@ export const DEFAULT_OPTIONS: PluginOptions = { export const PluginOptionSchema = Joi.object({ path: Joi.string().default(DEFAULT_OPTIONS.path), - archiveBasePath: Joi.string().default(DEFAULT_OPTIONS.archiveBasePath), + archiveBasePath: Joi.string() + .default(DEFAULT_OPTIONS.archiveBasePath) + .allow(null), routeBasePath: Joi.string() // '' not allowed, see https://github.com/facebook/docusaurus/issues/3374 // .allow('') diff --git a/website/docs/api/plugins/plugin-content-blog.md b/website/docs/api/plugins/plugin-content-blog.md index 2192981739..b456cc3125 100644 --- a/website/docs/api/plugins/plugin-content-blog.md +++ b/website/docs/api/plugins/plugin-content-blog.md @@ -46,7 +46,7 @@ Accepted fields: | `blogSidebarTitle` | `string` | `'Recent posts'` | Title of the blog sidebar. | | `routeBasePath` | `string` | `'blog'` | URL route for the blog section of your site. **DO NOT** include a trailing slash. Use `/` to put the blog at root path. | | `tagsBasePath` | `string` | `'tags'` | URL route for the tags list page of your site. It is prepended to the `routeBasePath`. | -| `archiveBasePath` | `string` | `'/archive'` | URL route for the archive blog section of your site. It is prepended to the `routeBasePath`. **DO NOT** include a trailing slash. | +| `archiveBasePath` | string \| null | `'/archive'` | URL route for the archive blog section of your site. It is prepended to the `routeBasePath`. **DO NOT** include a trailing slash. Use `null` to disable generation of archive. | | `include` | `string[]` | `['**/*.{md,mdx}']` | Matching files will be included and processed. | | `exclude` | `string[]` | _See example configuration_ | No route will be created for matching files. | | `postsPerPage` | number \| 'ALL' | `10` | Number of posts to show per page in the listing page. Use `'ALL'` to display all posts on one listing page. |