Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix title_meta handling in doc front matter #10879

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('validateBlogPostFrontMatter title_meta', () => {

describe('validateBlogPostFrontMatter sidebar_label', () => {
testField({
prefix: 'title_meta',
prefix: 'sidebar_label',
validFrontMatters: [
{sidebar_label: undefined},
{sidebar_label: ''},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ describe('validateDocFrontMatter title', () => {
});
});

describe('validateDocFrontMatter title_meta', () => {
testField({
prefix: 'title_meta',
validFrontMatters: [
{title_meta: undefined},
{title_meta: ''},
{title_meta: 'title'},
],
invalidFrontMatters: [
[{title_meta: null}, 'must be a string'],
[{title_meta: false}, 'must be a string'],
],
});
});

describe('validateDocFrontMatter hide_title', () => {
testField({
prefix: 'hide_title',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
id: Joi.string(),
// See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
title: Joi.string().allow(''),
title_meta: Joi.string().allow(''),
hide_title: Joi.boolean(),
hide_table_of_contents: Joi.boolean(),
keywords: Joi.array().items(Joi.string().required()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ declare module '@docusaurus/plugin-content-docs' {
* @see {@link DocMetadata.title}
*/
title?: string;
/**
* Will be used for SEO page metadata and override DocMetadata.title.
*/
title_meta?: string;
/**
* Front matter tags, unnormalized.
* @see {@link DocMetadata.tags}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function DocItemMetadata(): ReactNode {
const {metadata, frontMatter, assets} = useDoc();
return (
<PageMetadata
title={metadata.title}
title={frontMatter.title_meta ?? metadata.title}
description={metadata.description}
keywords={frontMatter.keywords}
image={assets.image ?? frontMatter.image}
Expand Down
Loading