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

custom frontmatter headline #1482

Merged
merged 3 commits into from
Sep 16, 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
5 changes: 5 additions & 0 deletions packages/ui/app/src/mdx/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <meta name="description"> tag in the HTML.
*/
Expand Down
6 changes: 4 additions & 2 deletions packages/ui/app/src/seo/getSeoProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function getSeoProps(

let ogMetadata: DocsV1Read.MetadataConfig = metadata ?? {};
let seoTitleFromMarkdownH1;
let frontmatterHeadline;

if (pageId != null) {
const page = pages[pageId];
Expand Down Expand Up @@ -95,8 +96,9 @@ export function getSeoProps(
}

seoTitleFromMarkdownH1 = extractHeadline(content);
frontmatterHeadline = frontmatter.headline;

seo.title ??= seoTitleFromMarkdownH1 ?? frontmatter.title;
seo.title ??= frontmatterHeadline ?? seoTitleFromMarkdownH1 ?? frontmatter.title;
seo.description ??= frontmatter.description ?? frontmatter.subtitle ?? frontmatter.excerpt;
}
}
Expand Down Expand Up @@ -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) {
Expand Down
Loading