mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-26 04:57:50 +02:00
feat(pages): Support frontMatter.slug
like docs and blog plugins (#11088)
This commit is contained in:
parent
ac0a6f7d5b
commit
5b944d6b64
8 changed files with 23 additions and 9 deletions
|
@ -1,5 +1,7 @@
|
|||
---
|
||||
title: MDX page
|
||||
description: my MDX page
|
||||
slug: /custom-mdx/slug
|
||||
---
|
||||
|
||||
MDX page
|
||||
|
|
|
@ -32,11 +32,12 @@ exports[`docusaurus-plugin-content-pages loads simple pages 1`] = `
|
|||
"frontMatter": {
|
||||
"custom_frontMatter": "added by parseFrontMatter",
|
||||
"description": "my MDX page",
|
||||
"slug": "/custom-mdx/slug",
|
||||
"title": "MDX page",
|
||||
},
|
||||
"lastUpdatedAt": undefined,
|
||||
"lastUpdatedBy": undefined,
|
||||
"permalink": "/hello/mdxPage",
|
||||
"permalink": "/custom-mdx/slug",
|
||||
"source": "@site/src/pages/hello/mdxPage.mdx",
|
||||
"title": "MDX page",
|
||||
"type": "mdx",
|
||||
|
@ -101,11 +102,12 @@ exports[`docusaurus-plugin-content-pages loads simple pages with french translat
|
|||
"frontMatter": {
|
||||
"custom_frontMatter": "added by parseFrontMatter",
|
||||
"description": "my MDX page",
|
||||
"slug": "/custom-mdx/slug",
|
||||
"title": "MDX page",
|
||||
},
|
||||
"lastUpdatedAt": undefined,
|
||||
"lastUpdatedBy": undefined,
|
||||
"permalink": "/fr/hello/mdxPage",
|
||||
"permalink": "/fr/custom-mdx/slug",
|
||||
"source": "@site/src/pages/hello/mdxPage.mdx",
|
||||
"title": "MDX page",
|
||||
"type": "mdx",
|
||||
|
@ -170,11 +172,12 @@ exports[`docusaurus-plugin-content-pages loads simple pages with last update 1`]
|
|||
"frontMatter": {
|
||||
"custom_frontMatter": "added by parseFrontMatter",
|
||||
"description": "my MDX page",
|
||||
"slug": "/custom-mdx/slug",
|
||||
"title": "MDX page",
|
||||
},
|
||||
"lastUpdatedAt": 1539502055000,
|
||||
"lastUpdatedBy": "Author",
|
||||
"permalink": "/hello/mdxPage",
|
||||
"permalink": "/custom-mdx/slug",
|
||||
"source": "@site/src/pages/hello/mdxPage.mdx",
|
||||
"title": "MDX page",
|
||||
"type": "mdx",
|
||||
|
|
|
@ -106,12 +106,13 @@ async function processPageSourceFile(
|
|||
|
||||
const source = path.join(contentPath, relativeSource);
|
||||
const aliasedSourcePath = aliasedSitePath(source, siteDir);
|
||||
const permalink = normalizeUrl([
|
||||
baseUrl,
|
||||
options.routeBasePath,
|
||||
encodePath(fileToPath(relativeSource)),
|
||||
]);
|
||||
|
||||
const filenameSlug = encodePath(fileToPath(relativeSource));
|
||||
|
||||
if (!isMarkdownSource(relativeSource)) {
|
||||
// For now, slug can't be customized for JSX pages
|
||||
const slug = filenameSlug;
|
||||
const permalink = normalizeUrl([baseUrl, options.routeBasePath, slug]);
|
||||
return {
|
||||
type: 'jsx',
|
||||
permalink,
|
||||
|
@ -131,6 +132,9 @@ async function processPageSourceFile(
|
|||
});
|
||||
const frontMatter = validatePageFrontMatter(unsafeFrontMatter);
|
||||
|
||||
const slug = frontMatter.slug ?? filenameSlug;
|
||||
const permalink = normalizeUrl([baseUrl, options.routeBasePath, slug]);
|
||||
|
||||
const pagesDirPath = await getFolderContainingFile(
|
||||
getContentPathList(contentPaths),
|
||||
relativeSource,
|
||||
|
|
|
@ -22,6 +22,7 @@ const PageFrontMatterSchema = Joi.object<PageFrontMatter>({
|
|||
description: Joi.string().allow(''),
|
||||
keywords: Joi.array().items(Joi.string().required()),
|
||||
image: URISchema,
|
||||
slug: Joi.string(),
|
||||
wrapperClassName: Joi.string(),
|
||||
hide_table_of_contents: Joi.boolean(),
|
||||
...FrontMatterTOCHeadingLevels,
|
||||
|
|
|
@ -37,6 +37,7 @@ declare module '@docusaurus/plugin-content-pages' {
|
|||
readonly title?: string;
|
||||
readonly description?: string;
|
||||
readonly image?: string;
|
||||
readonly slug?: string;
|
||||
readonly keywords?: string[];
|
||||
readonly wrapperClassName?: string;
|
||||
readonly hide_table_of_contents?: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue