mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-30 02:37:59 +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
|
title: MDX page
|
||||||
description: my MDX page
|
description: my MDX page
|
||||||
|
slug: /custom-mdx/slug
|
||||||
---
|
---
|
||||||
|
|
||||||
MDX page
|
MDX page
|
||||||
|
|
|
@ -32,11 +32,12 @@ exports[`docusaurus-plugin-content-pages loads simple pages 1`] = `
|
||||||
"frontMatter": {
|
"frontMatter": {
|
||||||
"custom_frontMatter": "added by parseFrontMatter",
|
"custom_frontMatter": "added by parseFrontMatter",
|
||||||
"description": "my MDX page",
|
"description": "my MDX page",
|
||||||
|
"slug": "/custom-mdx/slug",
|
||||||
"title": "MDX page",
|
"title": "MDX page",
|
||||||
},
|
},
|
||||||
"lastUpdatedAt": undefined,
|
"lastUpdatedAt": undefined,
|
||||||
"lastUpdatedBy": undefined,
|
"lastUpdatedBy": undefined,
|
||||||
"permalink": "/hello/mdxPage",
|
"permalink": "/custom-mdx/slug",
|
||||||
"source": "@site/src/pages/hello/mdxPage.mdx",
|
"source": "@site/src/pages/hello/mdxPage.mdx",
|
||||||
"title": "MDX page",
|
"title": "MDX page",
|
||||||
"type": "mdx",
|
"type": "mdx",
|
||||||
|
@ -101,11 +102,12 @@ exports[`docusaurus-plugin-content-pages loads simple pages with french translat
|
||||||
"frontMatter": {
|
"frontMatter": {
|
||||||
"custom_frontMatter": "added by parseFrontMatter",
|
"custom_frontMatter": "added by parseFrontMatter",
|
||||||
"description": "my MDX page",
|
"description": "my MDX page",
|
||||||
|
"slug": "/custom-mdx/slug",
|
||||||
"title": "MDX page",
|
"title": "MDX page",
|
||||||
},
|
},
|
||||||
"lastUpdatedAt": undefined,
|
"lastUpdatedAt": undefined,
|
||||||
"lastUpdatedBy": undefined,
|
"lastUpdatedBy": undefined,
|
||||||
"permalink": "/fr/hello/mdxPage",
|
"permalink": "/fr/custom-mdx/slug",
|
||||||
"source": "@site/src/pages/hello/mdxPage.mdx",
|
"source": "@site/src/pages/hello/mdxPage.mdx",
|
||||||
"title": "MDX page",
|
"title": "MDX page",
|
||||||
"type": "mdx",
|
"type": "mdx",
|
||||||
|
@ -170,11 +172,12 @@ exports[`docusaurus-plugin-content-pages loads simple pages with last update 1`]
|
||||||
"frontMatter": {
|
"frontMatter": {
|
||||||
"custom_frontMatter": "added by parseFrontMatter",
|
"custom_frontMatter": "added by parseFrontMatter",
|
||||||
"description": "my MDX page",
|
"description": "my MDX page",
|
||||||
|
"slug": "/custom-mdx/slug",
|
||||||
"title": "MDX page",
|
"title": "MDX page",
|
||||||
},
|
},
|
||||||
"lastUpdatedAt": 1539502055000,
|
"lastUpdatedAt": 1539502055000,
|
||||||
"lastUpdatedBy": "Author",
|
"lastUpdatedBy": "Author",
|
||||||
"permalink": "/hello/mdxPage",
|
"permalink": "/custom-mdx/slug",
|
||||||
"source": "@site/src/pages/hello/mdxPage.mdx",
|
"source": "@site/src/pages/hello/mdxPage.mdx",
|
||||||
"title": "MDX page",
|
"title": "MDX page",
|
||||||
"type": "mdx",
|
"type": "mdx",
|
||||||
|
|
|
@ -106,12 +106,13 @@ async function processPageSourceFile(
|
||||||
|
|
||||||
const source = path.join(contentPath, relativeSource);
|
const source = path.join(contentPath, relativeSource);
|
||||||
const aliasedSourcePath = aliasedSitePath(source, siteDir);
|
const aliasedSourcePath = aliasedSitePath(source, siteDir);
|
||||||
const permalink = normalizeUrl([
|
|
||||||
baseUrl,
|
const filenameSlug = encodePath(fileToPath(relativeSource));
|
||||||
options.routeBasePath,
|
|
||||||
encodePath(fileToPath(relativeSource)),
|
|
||||||
]);
|
|
||||||
if (!isMarkdownSource(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 {
|
return {
|
||||||
type: 'jsx',
|
type: 'jsx',
|
||||||
permalink,
|
permalink,
|
||||||
|
@ -131,6 +132,9 @@ async function processPageSourceFile(
|
||||||
});
|
});
|
||||||
const frontMatter = validatePageFrontMatter(unsafeFrontMatter);
|
const frontMatter = validatePageFrontMatter(unsafeFrontMatter);
|
||||||
|
|
||||||
|
const slug = frontMatter.slug ?? filenameSlug;
|
||||||
|
const permalink = normalizeUrl([baseUrl, options.routeBasePath, slug]);
|
||||||
|
|
||||||
const pagesDirPath = await getFolderContainingFile(
|
const pagesDirPath = await getFolderContainingFile(
|
||||||
getContentPathList(contentPaths),
|
getContentPathList(contentPaths),
|
||||||
relativeSource,
|
relativeSource,
|
||||||
|
|
|
@ -22,6 +22,7 @@ const PageFrontMatterSchema = Joi.object<PageFrontMatter>({
|
||||||
description: Joi.string().allow(''),
|
description: Joi.string().allow(''),
|
||||||
keywords: Joi.array().items(Joi.string().required()),
|
keywords: Joi.array().items(Joi.string().required()),
|
||||||
image: URISchema,
|
image: URISchema,
|
||||||
|
slug: Joi.string(),
|
||||||
wrapperClassName: Joi.string(),
|
wrapperClassName: Joi.string(),
|
||||||
hide_table_of_contents: Joi.boolean(),
|
hide_table_of_contents: Joi.boolean(),
|
||||||
...FrontMatterTOCHeadingLevels,
|
...FrontMatterTOCHeadingLevels,
|
||||||
|
|
|
@ -37,6 +37,7 @@ declare module '@docusaurus/plugin-content-pages' {
|
||||||
readonly title?: string;
|
readonly title?: string;
|
||||||
readonly description?: string;
|
readonly description?: string;
|
||||||
readonly image?: string;
|
readonly image?: string;
|
||||||
|
readonly slug?: string;
|
||||||
readonly keywords?: string[];
|
readonly keywords?: string[];
|
||||||
readonly wrapperClassName?: string;
|
readonly wrapperClassName?: string;
|
||||||
readonly hide_table_of_contents?: string;
|
readonly hide_table_of_contents?: string;
|
||||||
|
|
|
@ -37,7 +37,7 @@ import Readme from "../README.mdx"
|
||||||
- [Tabs tests](/tests/pages/tabs-tests)
|
- [Tabs tests](/tests/pages/tabs-tests)
|
||||||
- [z-index tests](/tests/pages/z-index-tests)
|
- [z-index tests](/tests/pages/z-index-tests)
|
||||||
- [Head metadata tests](/tests/pages/head-metadata)
|
- [Head metadata tests](/tests/pages/head-metadata)
|
||||||
- [Unlisted page](/tests/pages/unlisted)
|
- [Unlisted page](/tests/pages/my-custom/unlisted/slug)
|
||||||
- [Analytics](/tests/pages/analytics)
|
- [Analytics](/tests/pages/analytics)
|
||||||
- [History tests](/tests/pages/history-tests)
|
- [History tests](/tests/pages/history-tests)
|
||||||
- [Embeds](/tests/pages/embeds)
|
- [Embeds](/tests/pages/embeds)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
---
|
---
|
||||||
unlisted: true
|
unlisted: true
|
||||||
|
slug: /my-custom/unlisted/slug
|
||||||
---
|
---
|
||||||
|
|
||||||
# Unlisted page
|
# Unlisted page
|
||||||
|
|
|
@ -113,6 +113,7 @@ Accepted fields:
|
||||||
| `description` | `string` | The first line of Markdown content | The description of your page, which will become the `<meta name="description" content="..."/>` and `<meta property="og:description" content="..."/>` in `<head>`, used by search engines. |
|
| `description` | `string` | The first line of Markdown content | The description of your page, which will become the `<meta name="description" content="..."/>` and `<meta property="og:description" content="..."/>` in `<head>`, used by search engines. |
|
||||||
| `keywords` | `string[]` | `undefined` | Keywords meta tag, which will become the `<meta name="keywords" content="keyword1,keyword2,..."/>` in `<head>`, used by search engines. |
|
| `keywords` | `string[]` | `undefined` | Keywords meta tag, which will become the `<meta name="keywords" content="keyword1,keyword2,..."/>` in `<head>`, used by search engines. |
|
||||||
| `image` | `string` | `undefined` | Cover or thumbnail image that will be used as the `<meta property="og:image" content="..."/>` in the `<head>`, enhancing link previews on social media and messaging platforms. |
|
| `image` | `string` | `undefined` | Cover or thumbnail image that will be used as the `<meta property="og:image" content="..."/>` in the `<head>`, enhancing link previews on social media and messaging platforms. |
|
||||||
|
| `slug` | `string` | File path | Allows to customize the page URL (`/<routeBasePath>/<slug>`). Support multiple patterns: `slug: my-page`, `slug: /my/page`, slug: `/`. |
|
||||||
| `wrapperClassName` | `string` | | Class name to be added to the wrapper element to allow targeting specific page content. |
|
| `wrapperClassName` | `string` | | Class name to be added to the wrapper element to allow targeting specific page content. |
|
||||||
| `hide_table_of_contents` | `boolean` | `false` | Whether to hide the table of contents to the right. |
|
| `hide_table_of_contents` | `boolean` | `false` | Whether to hide the table of contents to the right. |
|
||||||
| `draft` | `boolean` | `false` | Draft pages will only be available during development. |
|
| `draft` | `boolean` | `false` | Draft pages will only be available during development. |
|
||||||
|
@ -131,6 +132,7 @@ description: Markdown page SEO description
|
||||||
wrapperClassName: markdown-page
|
wrapperClassName: markdown-page
|
||||||
hide_table_of_contents: false
|
hide_table_of_contents: false
|
||||||
draft: true
|
draft: true
|
||||||
|
slug: /markdown-page
|
||||||
---
|
---
|
||||||
|
|
||||||
Markdown page content
|
Markdown page content
|
||||||
|
|
Loading…
Add table
Reference in a new issue