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

feat(blog): Add frontMatter.title_meta to override title for SEO #10586

Merged
merged 6 commits into from
Oct 31, 2024
Merged
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 @@ -93,6 +93,21 @@ describe('validateBlogPostFrontMatter title', () => {
{title: ''},
{title: 'title'},
],
invalidFrontMatters: [
[{title: null}, 'must be a string'],
[{title: false}, 'must be a string'],
],
});
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const FrontMatterAuthorErrorMessage =
const BlogFrontMatterSchema = Joi.object<BlogPostFrontMatter>({
id: Joi.string(),
title: Joi.string().allow(''),
title_meta: Joi.string(),
description: Joi.string().allow(''),
tags: FrontMatterTagsSchema,
date: Joi.date().raw(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ declare module '@docusaurus/plugin-content-blog' {
* @see {@link BlogPostMetadata.title}
*/
title?: string;
/**
* Will be used for SEO page metadata and override BlogPostMetadata.title.
* @see {@link BlogPostMetadata.title_meta}
*/
title_meta?: string;
/**
* Will override the default excerpt.
* @see {@link BlogPostMetadata.description}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function BlogPostPageMetadata(): JSX.Element {
const image = assets.image ?? frontMatter.image;
return (
<PageMetadata
title={title}
title={frontMatter.title_meta ?? title}
description={description}
keywords={keywords}
image={image}>
Expand Down
1 change: 1 addition & 0 deletions website/docs/api/plugins/plugin-content-docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ Accepted fields:
| --- | --- | --- | --- |
| `id` | `string` | file path (including folders, without the extension) | A unique document ID. |
| `title` | `string` | Markdown title or `id` | The text title of your document. Used for the page metadata and as a fallback value in multiple places (sidebar, next/previous buttons...). Automatically added at the top of your doc if it does not contain any Markdown title. |
| `title_meta` | `string` | `frontMatter.title` | The SEO metadata title of your document used in `<head>` for `<title>` and `og:title`. Permits to override `frontMatter.title` when the displayed title and SEO title should be different. |
| `pagination_label` | `string` | `sidebar_label` or `title` | The text used in the document next/previous buttons for this document. |
| `sidebar_label` | `string` | `title` | The text shown in the document sidebar for this document. |
| `sidebar_position` | `number` | Default ordering | Controls the position of a doc inside the generated sidebar slice when using `autogenerated` sidebar items. See also [Autogenerated sidebar metadata](/docs/sidebar/autogenerated#autogenerated-sidebar-metadata). |
Expand Down