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 1 commit
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
3 changes: 3 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ async function processBlogSourceFile(
const date = await getDate();

const title = frontMatter.title ?? contentTitle ?? parsedBlogFileName.text;
const title_meta = frontMatter.title_meta ?? frontMatter.title ?? contentTitle ?? parsedBlogFileName.text;

const description = frontMatter.description ?? excerpt ?? '';

const slug = frontMatter.slug ?? parsedBlogFileName.slug;
Expand Down Expand Up @@ -365,6 +367,7 @@ async function processBlogSourceFile(
editUrl: getBlogEditUrl(),
source: aliasedSource,
title,
title_meta,
description,
date,
tags,
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 override the title collected from the frontMatter.
* @see {@link BlogPostMetadata.title_meta}
ilg-ul marked this conversation as resolved.
Show resolved Hide resolved
*/
title_meta?: string;
/**
* Will override the default excerpt.
* @see {@link BlogPostMetadata.description}
Expand Down Expand Up @@ -249,6 +254,10 @@ declare module '@docusaurus/plugin-content-blog' {
* Used to generate the page h1 heading, tab title, and pagination title.
*/
readonly title: string;
/**
* Used to generate the <head><title> and <meta>.
*/
readonly title_meta?: string;
ilg-ul marked this conversation as resolved.
Show resolved Hide resolved
/**
* The publish date of the post. On client side, this will be serialized
* into a string.
Expand Down
3 changes: 3 additions & 0 deletions packages/docusaurus-plugin-content-docs/src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ async function doProcessDocMetadata({
// pagination buttons... frontMatter.title should be used in priority over
// contentTitle (because it can contain markdown/JSX syntax)
const title: string = frontMatter.title ?? contentTitle ?? baseID;
// To be passed to `<PageMetadata>`. Will override the title.
const title_meta: string = frontMatter.title_meta ?? frontMatter.title ?? contentTitle ?? baseID;
ilg-ul marked this conversation as resolved.
Show resolved Hide resolved

const description: string = frontMatter.description ?? excerpt ?? '';

Expand Down Expand Up @@ -224,6 +226,7 @@ async function doProcessDocMetadata({
return {
id,
title,
title_meta,
ilg-ul marked this conversation as resolved.
Show resolved Hide resolved
description,
source: aliasedSitePath(filePath, siteDir),
sourceDirName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ declare module '@docusaurus/plugin-content-docs' {
* @see {@link DocMetadata.title}
*/
title?: string;
/**
* Will override the title collected from the frontMatter.
* @see {@link DocMetadata.title_meta}
*/
title_meta?: string;
ilg-ul marked this conversation as resolved.
Show resolved Hide resolved
/**
* Front matter tags, unnormalized.
* @see {@link DocMetadata.tags}
Expand Down Expand Up @@ -411,6 +416,10 @@ declare module '@docusaurus/plugin-content-docs' {
* Used to generate the page h1 heading, tab title, and pagination title.
*/
title: string;
/**
* Used to generate the <head><title> and <meta>.
*/
title_meta?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

/**
* Description used in the meta. Could be an empty string (empty content)
*/
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={metadata.title_meta ?? title}
ilg-ul marked this conversation as resolved.
Show resolved Hide resolved
description={description}
keywords={keywords}
image={image}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function DocItemMetadata(): JSX.Element {
const {metadata, frontMatter, assets} = useDoc();
return (
<PageMetadata
title={metadata.title}
ilg-ul marked this conversation as resolved.
Show resolved Hide resolved
title={metadata.title_meta ?? metadata.title}
description={metadata.description}
keywords={frontMatter.keywords}
image={assets.image ?? frontMatter.image}
Expand Down
Loading