feat(content-blog): allow disabling generating archive (#6415)

This commit is contained in:
Joshua Chen 2022-01-20 21:52:19 +08:00 committed by GitHub
parent 2a5407f6bd
commit d506bca12d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 22 deletions

View file

@ -242,25 +242,26 @@ export default async function pluginContentBlog(
? blogPosts ? blogPosts
: blogPosts.slice(0, options.blogSidebarCount); : blogPosts.slice(0, options.blogSidebarCount);
const archiveUrl = normalizeUrl([ if (archiveBasePath) {
baseUrl, const archiveUrl = normalizeUrl([
routeBasePath, baseUrl,
archiveBasePath, routeBasePath,
]); archiveBasePath,
]);
// creates a blog archive route // creates a blog archive route
const archiveProp = await createData( const archiveProp = await createData(
`${docuHash(archiveUrl)}.json`, `${docuHash(archiveUrl)}.json`,
JSON.stringify({blogPosts}, null, 2), JSON.stringify({blogPosts}, null, 2),
); );
addRoute({ addRoute({
path: archiveUrl, path: archiveUrl,
component: '@theme/BlogArchivePage', component: '@theme/BlogArchivePage',
exact: true, exact: true,
modules: { modules: {
archive: aliasedSource(archiveProp), archive: aliasedSource(archiveProp),
}, },
}); });
}
// This prop is useful to provide the blog list sidebar // This prop is useful to provide the blog list sidebar
const sidebarProp = await createData( const sidebarProp = await createData(

View file

@ -112,7 +112,7 @@ declare module '@docusaurus/plugin-content-blog' {
path: string; path: string;
routeBasePath: string; routeBasePath: string;
tagsBasePath: string; tagsBasePath: string;
archiveBasePath: string; archiveBasePath: string | null;
include: string[]; include: string[];
exclude: string[]; exclude: string[];
postsPerPage: number | 'ALL'; postsPerPage: number | 'ALL';

View file

@ -47,7 +47,9 @@ export const DEFAULT_OPTIONS: PluginOptions = {
export const PluginOptionSchema = Joi.object<PluginOptions>({ export const PluginOptionSchema = Joi.object<PluginOptions>({
path: Joi.string().default(DEFAULT_OPTIONS.path), 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() routeBasePath: Joi.string()
// '' not allowed, see https://github.com/facebook/docusaurus/issues/3374 // '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
// .allow('') // .allow('')

View file

@ -46,7 +46,7 @@ Accepted fields:
| `blogSidebarTitle` | `string` | `'Recent posts'` | Title of the blog sidebar. | | `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. | | `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`. | | `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` | <code>string \| null</code> | `'/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. | | `include` | `string[]` | `['**/*.{md,mdx}']` | Matching files will be included and processed. |
| `exclude` | `string[]` | _See example configuration_ | No route will be created for matching files. | | `exclude` | `string[]` | _See example configuration_ | No route will be created for matching files. |
| `postsPerPage` | <code>number \| 'ALL'</code> | `10` | Number of posts to show per page in the listing page. Use `'ALL'` to display all posts on one listing page. | | `postsPerPage` | <code>number \| 'ALL'</code> | `10` | Number of posts to show per page in the listing page. Use `'ALL'` to display all posts on one listing page. |