Skip to content

Commit 2781aab

Browse files
committed
feat: add per-page opengraph images via transformHead hook
1 parent 5a33b0d commit 2781aab

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

.vitepress/config.mts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ export default defineConfig({
2020
'perspectives/the-spec-driven-shift/post-1': 'perspectives/the-spec-driven-shift/your-ai-codebase-is-a-ticking-time-bomb',
2121
'perspectives/the-spec-driven-shift/post-2': 'perspectives/the-spec-driven-shift/stop-calling-it-a-spec-if-its-not-specific',
2222
},
23+
transformHead({ pageData }) {
24+
const head: Array<[string, Record<string, string>]> = []
25+
const image = pageData.frontmatter.image
26+
const title = pageData.frontmatter.title || pageData.title
27+
const description = pageData.frontmatter.description || pageData.description
28+
29+
if (title) {
30+
head.push(['meta', { property: 'og:title', content: title }])
31+
head.push(['meta', { name: 'twitter:title', content: title }])
32+
}
33+
if (description) {
34+
head.push(['meta', { property: 'og:description', content: description }])
35+
head.push(['meta', { name: 'twitter:description', content: description }])
36+
}
37+
if (image) {
38+
head.push(['meta', { property: 'og:image', content: `${siteUrl}${image}` }])
39+
head.push(['meta', { name: 'twitter:image', content: `${siteUrl}${image}` }])
40+
}
41+
42+
return head
43+
},
2344
head: [
2445
// Favicons
2546
[

0 commit comments

Comments
 (0)