mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-17 16:47:56 +02:00
feat(pages): add support for missing SEO front matter + improve SEO docs (#9071)
Co-authored-by: Thad Guidry <thadguidry@gmail.com>
This commit is contained in:
parent
117cbac702
commit
9866af7f44
11 changed files with 146 additions and 22 deletions
|
@ -10,12 +10,17 @@ import {
|
|||
validateFrontMatter,
|
||||
FrontMatterTOCHeadingLevels,
|
||||
ContentVisibilitySchema,
|
||||
URISchema,
|
||||
} from '@docusaurus/utils-validation';
|
||||
import type {FrontMatter} from '@docusaurus/plugin-content-pages';
|
||||
import type {PageFrontMatter} from '@docusaurus/plugin-content-pages';
|
||||
|
||||
const PageFrontMatterSchema = Joi.object<FrontMatter>({
|
||||
title: Joi.string(),
|
||||
description: Joi.string(),
|
||||
const PageFrontMatterSchema = Joi.object<PageFrontMatter>({
|
||||
// See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
|
||||
title: Joi.string().allow(''),
|
||||
// See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
|
||||
description: Joi.string().allow(''),
|
||||
keywords: Joi.array().items(Joi.string().required()),
|
||||
image: URISchema,
|
||||
wrapperClassName: Joi.string(),
|
||||
hide_table_of_contents: Joi.boolean(),
|
||||
...FrontMatterTOCHeadingLevels,
|
||||
|
@ -23,6 +28,6 @@ const PageFrontMatterSchema = Joi.object<FrontMatter>({
|
|||
|
||||
export function validatePageFrontMatter(frontMatter: {
|
||||
[key: string]: unknown;
|
||||
}): FrontMatter {
|
||||
}): PageFrontMatter {
|
||||
return validateFrontMatter(frontMatter, PageFrontMatterSchema);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import type {
|
|||
PluginOptions,
|
||||
Metadata,
|
||||
LoadedContent,
|
||||
PageFrontMatter,
|
||||
} from '@docusaurus/plugin-content-pages';
|
||||
|
||||
export function getContentPathList(contentPaths: PagesContentPaths): string[] {
|
||||
|
@ -234,6 +235,15 @@ export default function pluginContentPages(
|
|||
`${docuHash(aliasedSource)}.json`,
|
||||
);
|
||||
},
|
||||
// Assets allow to convert some relative images paths to
|
||||
// require(...) calls
|
||||
createAssets: ({
|
||||
frontMatter,
|
||||
}: {
|
||||
frontMatter: PageFrontMatter;
|
||||
}) => ({
|
||||
image: frontMatter.image,
|
||||
}),
|
||||
markdownConfig: siteConfig.markdown,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -9,6 +9,10 @@ declare module '@docusaurus/plugin-content-pages' {
|
|||
import type {MDXOptions} from '@docusaurus/mdx-loader';
|
||||
import type {LoadContext, Plugin} from '@docusaurus/types';
|
||||
|
||||
export type Assets = {
|
||||
image?: string;
|
||||
};
|
||||
|
||||
export type PluginOptions = MDXOptions & {
|
||||
id?: string;
|
||||
path: string;
|
||||
|
@ -20,9 +24,11 @@ declare module '@docusaurus/plugin-content-pages' {
|
|||
|
||||
export type Options = Partial<PluginOptions>;
|
||||
|
||||
export type FrontMatter = {
|
||||
export type PageFrontMatter = {
|
||||
readonly title?: string;
|
||||
readonly description?: string;
|
||||
readonly image?: string;
|
||||
readonly keywords?: string[];
|
||||
readonly wrapperClassName?: string;
|
||||
readonly hide_table_of_contents?: string;
|
||||
readonly toc_min_heading_level?: number;
|
||||
|
@ -41,7 +47,7 @@ declare module '@docusaurus/plugin-content-pages' {
|
|||
type: 'mdx';
|
||||
permalink: string;
|
||||
source: string;
|
||||
frontMatter: FrontMatter & {[key: string]: unknown};
|
||||
frontMatter: PageFrontMatter & {[key: string]: unknown};
|
||||
title?: string;
|
||||
description?: string;
|
||||
unlisted: boolean;
|
||||
|
@ -61,11 +67,16 @@ declare module '@theme/MDXPage' {
|
|||
import type {LoadedMDXContent} from '@docusaurus/mdx-loader';
|
||||
import type {
|
||||
MDXPageMetadata,
|
||||
FrontMatter,
|
||||
PageFrontMatter,
|
||||
Assets,
|
||||
} from '@docusaurus/plugin-content-pages';
|
||||
|
||||
export interface Props {
|
||||
readonly content: LoadedMDXContent<FrontMatter, MDXPageMetadata>;
|
||||
readonly content: LoadedMDXContent<
|
||||
PageFrontMatter,
|
||||
MDXPageMetadata,
|
||||
Assets
|
||||
>;
|
||||
}
|
||||
|
||||
export default function MDXPage(props: Props): JSX.Element;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue