@ -1,6 +1,7 @@
import {
import {
defineConfig ,
defineConfig ,
resolveSiteDataByRoute ,
resolveSiteDataByRoute ,
type ConfigEnv ,
type HeadConfig
type HeadConfig
} from 'vitepress'
} from 'vitepress'
import {
import {
@ -12,137 +13,160 @@ import llmstxt from 'vitepress-plugin-llms'
const prod = ! ! process . env . NETLIFY
const prod = ! ! process . env . NETLIFY
export default defineConfig ( {
export default ( ctx : ConfigEnv ) = >
title : 'VitePress' ,
defineConfig ( {
title : 'VitePress' ,
rewrites : {
rewrites : {
'en/:rest*' : ':rest*'
'en/:rest*' : ':rest*'
} ,
} ,
lastUpdated : true ,
lastUpdated : true ,
cleanUrls : true ,
cleanUrls : true ,
metaChunk : true ,
metaChunk : true ,
markdown : {
markdown : {
math : true ,
math : true ,
codeTransformers : [
codeTransformers : [
// We use `[!!code` in demo to prevent transformation, here we revert it back.
// We use `[!!code` in demo to prevent transformation, here we revert it back.
{
{
postprocess ( code ) {
postprocess ( code ) {
return code . replace ( /\[\!\!code/g , '[!code' )
return code . replace ( /\[\!\!code/g , '[!code' )
}
}
] ,
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 '复制代码'
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 )
}
}
] ,
} ,
config ( md ) {
// TODO: remove when https://github.com/vuejs/vitepress/issues/4431 is fixed
sitemap : {
const fence = md . renderer . rules . fence !
hostname : 'https://vitepress.dev' ,
md . renderer . rules . fence = function ( tokens , idx , options , env , self ) {
transformItems ( items ) {
const { localeIndex = 'root' } = env
return items . filter ( ( item ) = > ! item . url . includes ( 'migration' ) )
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 '复制代码'
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 : {
head : [
hostname : 'https://vitepress.dev' ,
[
transformItems ( items ) {
'link' ,
return items . filter ( ( item ) = > ! item . url . includes ( 'migration' ) )
{ 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' } ] ,
[ 'meta' , { property : 'og:type' , content : 'website' } ] ,
[ 'meta' , { property : 'og:site_name' , content : 'VitePress' } ] ,
[
'meta' ,
{
property : 'og:image' ,
content : 'https://vitepress.dev/vitepress-og.jpg'
}
] ,
[ 'meta' , { property : 'og:url' , content : 'https://vitepress.dev/' } ] ,
[
'script' ,
{
src : 'https://cdn.usefathom.com/script.js' ,
'data-site' : 'AZBRSFGG' ,
'data-spa' : 'auto' ,
defer : ''
}
]
] ,
/* prettier-ignore */
themeConfig : {
head : [
logo : { src : '/vitepress-logo-mini.svg' , width : 24 , height : 24 } ,
[ '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' } ] ,
[ 'meta' , { property : 'og:type' , content : 'website' } ] ,
[ 'meta' , { property : 'og:site_name' , content : 'VitePress' } ] ,
[ 'meta' , { property : 'og:image' , content : 'https://vitepress.dev/vitepress-og.jpg' } ] ,
[ 'meta' , { property : 'og:url' , content : 'https://vitepress.dev/' } ] ,
[ 'script' , { src : 'https://cdn.usefathom.com/script.js' , 'data-site' : 'AZBRSFGG' , 'data-spa' : 'auto' , defer : '' } ]
] ,
themeConfig : {
socialLinks : [
logo : { src : '/vitepress-logo-mini.svg' , width : 24 , height : 24 } ,
{ icon : 'github' , link : 'https://github.com/vuejs/vitepress' }
] ,
socialLinks : [
search : {
{ icon : 'github' , link : 'https://github.com/vuejs/vitepress' }
provider : 'algolia' ,
] ,
options : {
appId : '8J64VVRP8K' ,
apiKey : '52f578a92b88ad6abde815aae2b0ad7c' ,
indexName : 'vitepress'
}
} ,
search : {
carbonAds : { code : 'CEBDT27Y' , placement : 'vuejsorg' }
provider : 'algolia' ,
options : {
appId : '8J64VVRP8K' ,
apiKey : '52f578a92b88ad6abde815aae2b0ad7c' ,
indexName : 'vitepress'
}
} ,
} ,
carbonAds : { code : 'CEBDT27Y' , placement : 'vuejsorg' }
locales : {
} ,
root : { label : 'English' } ,
zh : { label : '简体中文' } ,
pt : { label : 'Português' } ,
ru : { label : 'Русский' } ,
es : { label : 'Español' } ,
ko : { label : '한국어' } ,
fa : { label : 'فارسی' }
} ,
locales : {
vite : {
root : { label : 'English' } ,
plugins : [
zh : { label : '简体中文' } ,
groupIconVitePlugin ( {
pt : { label : 'Português' } ,
customIcon : {
ru : { label : 'Русский' } ,
vitepress : localIconLoader (
es : { label : 'Español' } ,
import . meta . url ,
ko : { label : '한국어' } ,
'../public/vitepress-logo-mini.svg'
fa : { label : 'فارسی' }
) ,
} ,
firebase : 'logos:firebase'
}
} ) ,
prod &&
llmstxt ( {
workDir : 'en' ,
ignoreFiles : [ 'index.md' ]
} )
] ,
experimental : {
enableNativePlugin : ctx.command === 'build'
}
} ,
vite : {
transformPageData : prod
plugins : [
? ( pageData , ctx ) = > {
groupIconVitePlugin ( {
const site = resolveSiteDataByRoute (
customIcon : {
ctx . siteConfig . site ,
vitepress : localIconLoader (
pageData . relativePath
import . meta . url ,
)
'../public/vitepress-logo-mini.svg'
const title = ` ${ pageData . title || site . title } | ${ pageData . description || site . description } `
) ,
; ( ( pageData . frontmatter . head ? ? = [ ] ) as HeadConfig [ ] ) . push (
firebase : 'logos:firebase'
[ 'meta' , { property : 'og:locale' , content : site.lang } ] ,
[ 'meta' , { property : 'og:title' , content : title } ]
)
}
}
} ) ,
: undefined
prod &&
} )
llmstxt ( {
workDir : 'en' ,
ignoreFiles : [ 'index.md' ]
} )
]
} ,
transformPageData : prod
? ( pageData , ctx ) = > {
const site = resolveSiteDataByRoute (
ctx . siteConfig . site ,
pageData . relativePath
)
const title = ` ${ pageData . title || site . title } | ${ pageData . description || site . description } `
; ( ( pageData . frontmatter . head ? ? = [ ] ) as HeadConfig [ ] ) . push (
[ 'meta' , { property : 'og:locale' , content : site.lang } ] ,
[ 'meta' , { property : 'og:title' , content : title } ]
)
}
: undefined
} )