From 4f5c53a30e15fafa8e84044eae0c794e48cb345c Mon Sep 17 00:00:00 2001 From: Rohin Bhargava Date: Fri, 13 Sep 2024 19:16:15 -0400 Subject: [PATCH 1/2] custom frontmatter headline --- packages/ui/app/src/mdx/frontmatter.ts | 5 +++++ packages/ui/app/src/seo/getSeoProp.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/ui/app/src/mdx/frontmatter.ts b/packages/ui/app/src/mdx/frontmatter.ts index 7c9a333d24..4bede9cd0e 100644 --- a/packages/ui/app/src/mdx/frontmatter.ts +++ b/packages/ui/app/src/mdx/frontmatter.ts @@ -59,6 +59,11 @@ export interface FernDocsFrontmatter extends DocsV1Read.MetadataConfig { */ title?: string; + /** + * The SEO title of the page. If not set, the title will inherit what's set in the sidebar. + */ + headline?: string; + /** * The description of the page. This is used for the tag in the HTML. */ diff --git a/packages/ui/app/src/seo/getSeoProp.ts b/packages/ui/app/src/seo/getSeoProp.ts index 92eea1a381..1fbed510d9 100644 --- a/packages/ui/app/src/seo/getSeoProp.ts +++ b/packages/ui/app/src/seo/getSeoProp.ts @@ -96,7 +96,7 @@ export function getSeoProps( seoTitleFromMarkdownH1 = extractHeadline(content); - seo.title ??= seoTitleFromMarkdownH1 ?? frontmatter.title; + seo.title ??= frontmatter.headline ?? seoTitleFromMarkdownH1 ?? frontmatter.title; seo.description ??= frontmatter.description ?? frontmatter.subtitle ?? frontmatter.excerpt; } } From 766efdce0f7801e9c8c9ce93f14723ecae6ebb85 Mon Sep 17 00:00:00 2001 From: Rohin Bhargava Date: Mon, 16 Sep 2024 10:57:36 -0400 Subject: [PATCH 2/2] update title-template --- packages/ui/app/src/seo/getSeoProp.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/ui/app/src/seo/getSeoProp.ts b/packages/ui/app/src/seo/getSeoProp.ts index 1fbed510d9..46b78c92ef 100644 --- a/packages/ui/app/src/seo/getSeoProp.ts +++ b/packages/ui/app/src/seo/getSeoProp.ts @@ -59,6 +59,7 @@ export function getSeoProps( let ogMetadata: DocsV1Read.MetadataConfig = metadata ?? {}; let seoTitleFromMarkdownH1; + let frontmatterHeadline; if (pageId != null) { const page = pages[pageId]; @@ -95,8 +96,9 @@ export function getSeoProps( } seoTitleFromMarkdownH1 = extractHeadline(content); + frontmatterHeadline = frontmatter.headline; - seo.title ??= frontmatter.headline ?? seoTitleFromMarkdownH1 ?? frontmatter.title; + seo.title ??= frontmatterHeadline ?? seoTitleFromMarkdownH1 ?? frontmatter.title; seo.description ??= frontmatter.description ?? frontmatter.subtitle ?? frontmatter.excerpt; } } @@ -200,7 +202,7 @@ export function getSeoProps( seo.title ??= node.title; openGraph.siteName ??= title; if (title != null) { - seo.titleTemplate ??= seoTitleFromMarkdownH1 ?? `%s — ${title}`; + seo.titleTemplate ??= frontmatterHeadline ?? seoTitleFromMarkdownH1 ?? `%s — ${title}`; } if (favicon != null && files[favicon] != null) {