Skip to content

Commit 15a0278

Browse files
committed
docs: fix og tags
1 parent abc88d1 commit 15a0278

File tree

1 file changed

+23
-44
lines changed

1 file changed

+23
-44
lines changed

docs/.vitepress/config.ts

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import llmstxt from 'vitepress-plugin-llms'
1212

1313
const prod = !!process.env.NETLIFY
14+
const siteUrl = 'https://vitepress.dev'
1415

1516
export default defineConfig({
1617
title: 'VitePress',
@@ -71,41 +72,21 @@ export default defineConfig({
7172
},
7273

7374
sitemap: {
74-
hostname: 'https://vitepress.dev',
75+
hostname: siteUrl,
7576
transformItems(items) {
7677
return items.filter((item) => !item.url.includes('migration'))
7778
}
7879
},
7980

81+
// prettier-ignore
8082
head: [
81-
[
82-
'link',
83-
{ rel: 'icon', type: 'image/svg+xml', href: '/vitepress-logo-mini.svg' }
84-
],
85-
[
86-
'link',
87-
{ rel: 'icon', type: 'image/png', href: '/vitepress-logo-mini.png' }
88-
],
83+
['link', { rel: 'icon', type: 'image/svg+xml', href: '/vitepress-logo-mini.svg' }],
84+
['link', { rel: 'icon', type: 'image/png', href: '/vitepress-logo-mini.png' }],
8985
['meta', { name: 'theme-color', content: '#5f67ee' }],
9086
['meta', { property: 'og:type', content: 'website' }],
9187
['meta', { property: 'og:site_name', content: 'VitePress' }],
92-
[
93-
'meta',
94-
{
95-
property: 'og:image',
96-
content: 'https://vitepress.dev/vitepress-og.jpg'
97-
}
98-
],
99-
['meta', { property: 'og:url', content: 'https://vitepress.dev/' }],
100-
[
101-
'script',
102-
{
103-
src: 'https://cdn.usefathom.com/script.js',
104-
'data-site': 'AZBRSFGG',
105-
'data-spa': 'auto',
106-
defer: ''
107-
}
108-
]
88+
['meta', { property: 'og:image', content: new URL('/vitepress-og.jpg', siteUrl).href }],
89+
['script', { src: 'https://cdn.usefathom.com/script.js', 'data-site': 'AZBRSFGG', 'data-spa': 'auto', defer: '' }]
10990
],
11091

11192
themeConfig: {
@@ -153,28 +134,26 @@ export default defineConfig({
153134
firebase: 'logos:firebase'
154135
}
155136
}),
156-
prod &&
157-
llmstxt({
158-
workDir: 'en',
159-
ignoreFiles: ['index.md']
160-
})
137+
prod && llmstxt({ workDir: 'en', ignoreFiles: ['index.md'] })
161138
],
162139
experimental: {
163140
enableNativePlugin: true
164141
}
165142
},
166143

167-
transformPageData: prod
168-
? (pageData, ctx) => {
169-
const site = resolveSiteDataByRoute(
170-
ctx.siteConfig.site,
171-
pageData.relativePath
172-
)
173-
const title = `${pageData.title || site.title} | ${pageData.description || site.description}`
174-
;((pageData.frontmatter.head ??= []) as HeadConfig[]).push(
175-
['meta', { property: 'og:locale', content: site.lang }],
176-
['meta', { property: 'og:title', content: title }]
177-
)
178-
}
179-
: undefined
144+
// prettier-ignore
145+
transformPageData: prod ? (pageData, ctx) => {
146+
const url = new URL(pageData.relativePath.replace(/(?:(^|\/)index)?\.md$/, '$1'), siteUrl).href
147+
const site = resolveSiteDataByRoute(ctx.siteConfig.site, pageData.relativePath)
148+
const locale = site.lang.replace(/-([a-z]+)$/, '_$1')
149+
const title = `${pageData.title || site.title} | VitePress`
150+
const description = pageData.description || site.description
151+
152+
;((pageData.frontmatter.head ??= []) as HeadConfig[]).push(
153+
['meta', { property: 'og:url', content: url }],
154+
['meta', { property: 'og:locale', content: locale }],
155+
['meta', { property: 'og:title', content: title }],
156+
['meta', { property: 'og:description', content: description }]
157+
)
158+
} : undefined
180159
})

0 commit comments

Comments
 (0)