Skip to content

Commit 66853a4

Browse files
authored
Add ability to customize SEO title, image, etc. in MDX frontmatter (#191)
1 parent a2683c1 commit 66853a4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

layout/DocumentContext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { NextSeoProps } from 'next-seo'
12
import { Context, createContext } from 'react'
23

34
export type Frontmatter = {
45
title?: string
56
navTitle?: string
7+
seo?: NextSeoProps
68
}
79

810
export type OutlineItem = {

layout/MDXLayout.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,14 @@ export const MDXLayout = ({ pagePath, navItems, frontmatter, outline, children }
134134
return _highlightedOutlineItemId
135135
}, [outline, outlineItemIsInOrAboveView])
136136

137+
const seo = { ...(frontmatter?.seo ?? {}) }
138+
seo.title = seo.title ?? frontmatter?.title
139+
seo.title = `${seo.title ? `${seo.title} - ` : ''}The Graph Docs`
140+
137141
return (
138142
<NavContext.Provider value={{ pagePath, navItems, previousPage, currentPage, nextPage, currentGroup }}>
139143
<DocumentContext.Provider value={{ frontmatter, outline, markOutlineItem, highlightedOutlineItemId }}>
140-
<NextSeo title={`${frontmatter?.title ? `${frontmatter.title} - ` : ''} The Graph Docs`} />
144+
<NextSeo {...seo} />
141145

142146
<div
143147
sx={{

0 commit comments

Comments
 (0)