You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vitepress/docs/.vitepress/config.ts

179 lines
5.4 KiB

import {
defineConfig,
resolveSiteDataByRoute,
type HeadConfig
} from 'vitepress'
import {
groupIconMdPlugin,
groupIconVitePlugin,
localIconLoader
} from 'vitepress-plugin-group-icons'
import llmstxt from 'vitepress-plugin-llms'
const prod = !!process.env.NETLIFY
const siteUrl = 'https://vitepress.dev'
const ogImage = new URL('/vitepress-og.jpg', siteUrl).href
const localeToOgLocaleMap: Record<string, string> = {
root: 'en_US',
zh: 'zh_CN',
pt: 'pt_BR',
ru: 'ru_RU',
es: 'es_ES',
ko: 'ko_KR',
fa: 'fa_IR',
ja: 'ja_JP'
}
export default defineConfig({
title: 'VitePress',
rewrites: {
'en/:rest*': ':rest*'
},
lastUpdated: true,
cleanUrls: true,
metaChunk: true,
markdown: {
math: true,
codeTransformers: [
// We use `[!!code` and `@@include` in demo to prevent transformation,
// here we revert it back.
{
postprocess(code) {
return code
.replaceAll('[!!code', '[!code')
.replaceAll('@@include', '@include')
}
}
],
config(md) {
// TODO: remove when https://github.com/vuejs/vitepress/issues/4431 is fixed
const fence = md.renderer.rules.fence!
md.renderer.rules.fence = function (tokens, idx, options, env, self) {
const { localeIndex = 'root' } = env
const codeCopyButtonTitle = (() => {
switch (localeIndex) {
case 'es':
return 'Copiar código'
case 'fa':
return 'کپی کد'
case 'ko':
return '코드 복사'
case 'pt':
return 'Copiar código'
case 'ru':
return 'Скопировать код'
case 'zh':
return '复制代码'
case 'ja':
return 'コードをコピー'
default:
return 'Copy code'
}
})()
return fence(tokens, idx, options, env, self).replace(
'<button title="Copy Code" class="copy"></button>',
`<button title="${codeCopyButtonTitle}" class="copy"></button>`
)
}
md.use(groupIconMdPlugin)
}
},
sitemap: {
hostname: siteUrl,
transformItems(items) {
return items.filter((item) => !item.url.includes('migration'))
}
},
// prettier-ignore
head: [
['link', { rel: 'icon', type: 'image/svg+xml', href: '/vitepress-logo-mini.svg' }],
['link', { rel: 'icon', type: 'image/png', href: '/vitepress-logo-mini.png' }],
['meta', { name: 'theme-color', content: '#5f67ee' }],
['script', { src: 'https://cdn.usefathom.com/script.js', 'data-site': 'AZBRSFGG', 'data-spa': 'auto', defer: '' }]
],
themeConfig: {
logo: { src: '/vitepress-logo-mini.svg', width: 24, height: 24 },
socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }
],
search: {
provider: 'algolia',
options: {
appId: '8J64VVRP8K',
apiKey: '52f578a92b88ad6abde815aae2b0ad7c',
indexName: 'vitepress',
askAi: {
assistantId: 'YaVSonfX5bS8',
sidePanel: true
}
}
},
carbonAds: { code: 'CEBDT27Y', placement: 'vuejsorg' }
},
locales: {
root: { label: 'English', lang: 'en-US', dir: 'ltr' },
zh: { label: '简体中文', lang: 'zh-Hans', dir: 'ltr' },
pt: { label: 'Português', lang: 'pt-BR', dir: 'ltr' },
ru: { label: 'Русский', lang: 'ru-RU', dir: 'ltr' },
es: { label: 'Español', lang: 'es', dir: 'ltr' },
ko: { label: '한국어', lang: 'ko-KR', dir: 'ltr' },
fa: { label: 'فارسی', lang: 'fa-IR', dir: 'rtl' },
ja: { label: '日本語', lang: 'ja', dir: 'ltr' }
},
vite: {
plugins: [
groupIconVitePlugin({
customIcon: {
vitepress: localIconLoader(
import.meta.url,
'../public/vitepress-logo-mini.svg'
),
firebase: 'logos:firebase'
}
}),
prod && llmstxt({ workDir: 'en', ignoreFiles: ['index.md'] })
],
experimental: {
enableNativePlugin: true
}
},
// prettier-ignore
transformPageData: prod ? (pageData, ctx) => {
const url = new URL(pageData.relativePath.replace(/(?:(^|\/)index)?\.md$/, '$1'), siteUrl).href
const site = resolveSiteDataByRoute(ctx.siteConfig.site, pageData.relativePath)
const title = pageData.title ? `${pageData.title} | VitePress` : site.title
const description = pageData.description || site.description
const locale = localeToOgLocaleMap[site.localeIndex || 'root']
;((pageData.frontmatter.head ??= []) as HeadConfig[]).push(
['meta', { property: 'og:url', content: url }],
['meta', { property: 'og:title', content: title }],
['meta', { property: 'og:description', content: description }],
['meta', { property: 'og:type', content: 'website' }],
['meta', { property: 'og:locale', content: locale }],
['meta', { property: 'og:site_name', content: 'VitePress' }],
['meta', { property: 'og:image', content: ogImage }],
['meta', { property: 'og:image:secure_url', content: ogImage }],
['meta', { property: 'og:image:type', content: 'image/jpeg' }],
['meta', { property: 'og:image:width', content: '1280' }],
['meta', { property: 'og:image:height', content: '640' }],
['meta', { property: 'og:image:alt', content: 'VitePress' }],
['link', { rel: 'canonical', href: url }]
)
} : undefined
})