11import {
22 defineConfig ,
33 resolveSiteDataByRoute ,
4+ type ConfigEnv ,
45 type HeadConfig
56} from 'vitepress'
67import {
@@ -12,137 +13,160 @@ import llmstxt from 'vitepress-plugin-llms'
1213
1314const prod = ! ! process . env . NETLIFY
1415
15- export default defineConfig ( {
16- title : 'VitePress' ,
16+ export default ( ctx : ConfigEnv ) =>
17+ defineConfig ( {
18+ title : 'VitePress' ,
1719
18- rewrites : {
19- 'en/:rest*' : ':rest*'
20- } ,
20+ rewrites : {
21+ 'en/:rest*' : ':rest*'
22+ } ,
2123
22- lastUpdated : true ,
23- cleanUrls : true ,
24- metaChunk : true ,
24+ lastUpdated : true ,
25+ cleanUrls : true ,
26+ metaChunk : true ,
2527
26- markdown : {
27- math : true ,
28- codeTransformers : [
29- // We use `[!!code` in demo to prevent transformation, here we revert it back.
30- {
31- postprocess ( code ) {
32- return code . replace ( / \[ \! \! c o d e / g, '[!code' )
28+ markdown : {
29+ math : true ,
30+ codeTransformers : [
31+ // We use `[!!code` in demo to prevent transformation, here we revert it back.
32+ {
33+ postprocess ( code ) {
34+ return code . replace ( / \[ \! \! c o d e / g, '[!code' )
35+ }
36+ }
37+ ] ,
38+ config ( md ) {
39+ // TODO: remove when https://github.com/vuejs/vitepress/issues/4431 is fixed
40+ const fence = md . renderer . rules . fence !
41+ md . renderer . rules . fence = function ( tokens , idx , options , env , self ) {
42+ const { localeIndex = 'root' } = env
43+ const codeCopyButtonTitle = ( ( ) => {
44+ switch ( localeIndex ) {
45+ case 'es' :
46+ return 'Copiar código'
47+ case 'fa' :
48+ return 'کپی کد'
49+ case 'ko' :
50+ return '코드 복사'
51+ case 'pt' :
52+ return 'Copiar código'
53+ case 'ru' :
54+ return 'Скопировать код'
55+ case 'zh' :
56+ return '复制代码'
57+ default :
58+ return 'Copy code'
59+ }
60+ } ) ( )
61+ return fence ( tokens , idx , options , env , self ) . replace (
62+ '<button title="Copy Code" class="copy"></button>' ,
63+ `<button title="${ codeCopyButtonTitle } " class="copy"></button>`
64+ )
3365 }
66+ md . use ( groupIconMdPlugin )
3467 }
35- ] ,
36- config ( md ) {
37- // TODO: remove when https://github.com/vuejs/vitepress/issues/4431 is fixed
38- const fence = md . renderer . rules . fence !
39- md . renderer . rules . fence = function ( tokens , idx , options , env , self ) {
40- const { localeIndex = 'root' } = env
41- const codeCopyButtonTitle = ( ( ) => {
42- switch ( localeIndex ) {
43- case 'es' :
44- return 'Copiar código'
45- case 'fa' :
46- return 'کپی کد'
47- case 'ko' :
48- return '코드 복사'
49- case 'pt' :
50- return 'Copiar código'
51- case 'ru' :
52- return 'Скопировать код'
53- case 'zh' :
54- return '复制代码'
55- default :
56- return 'Copy code'
57- }
58- } ) ( )
59- return fence ( tokens , idx , options , env , self ) . replace (
60- '<button title="Copy Code" class="copy"></button>' ,
61- `<button title="${ codeCopyButtonTitle } " class="copy"></button>`
62- )
68+ } ,
69+
70+ sitemap : {
71+ hostname : 'https://vitepress.dev' ,
72+ transformItems ( items ) {
73+ return items . filter ( ( item ) => ! item . url . includes ( 'migration' ) )
6374 }
64- md . use ( groupIconMdPlugin )
65- }
66- } ,
75+ } ,
6776
68- sitemap : {
69- hostname : 'https://vitepress.dev' ,
70- transformItems ( items ) {
71- return items . filter ( ( item ) => ! item . url . includes ( 'migration' ) )
72- }
73- } ,
77+ head : [
78+ [
79+ 'link' ,
80+ { rel : 'icon' , type : 'image/svg+xml' , href : '/vitepress-logo-mini.svg' }
81+ ] ,
82+ [
83+ 'link' ,
84+ { rel : 'icon' , type : 'image/png' , href : '/vitepress-logo-mini.png' }
85+ ] ,
86+ [ 'meta' , { name : 'theme-color' , content : '#5f67ee' } ] ,
87+ [ 'meta' , { property : 'og:type' , content : 'website' } ] ,
88+ [ 'meta' , { property : 'og:site_name' , content : 'VitePress' } ] ,
89+ [
90+ 'meta' ,
91+ {
92+ property : 'og:image' ,
93+ content : 'https://vitepress.dev/vitepress-og.jpg'
94+ }
95+ ] ,
96+ [ 'meta' , { property : 'og:url' , content : 'https://vitepress.dev/' } ] ,
97+ [
98+ 'script' ,
99+ {
100+ src : 'https://cdn.usefathom.com/script.js' ,
101+ 'data-site' : 'AZBRSFGG' ,
102+ 'data-spa' : 'auto' ,
103+ defer : ''
104+ }
105+ ]
106+ ] ,
74107
75- /* prettier-ignore */
76- head : [
77- [ 'link' , { rel : 'icon' , type : 'image/svg+xml' , href : '/vitepress-logo-mini.svg' } ] ,
78- [ 'link' , { rel : 'icon' , type : 'image/png' , href : '/vitepress-logo-mini.png' } ] ,
79- [ 'meta' , { name : 'theme-color' , content : '#5f67ee' } ] ,
80- [ 'meta' , { property : 'og:type' , content : 'website' } ] ,
81- [ 'meta' , { property : 'og:site_name' , content : 'VitePress' } ] ,
82- [ 'meta' , { property : 'og:image' , content : 'https://vitepress.dev/vitepress-og.jpg' } ] ,
83- [ 'meta' , { property : 'og:url' , content : 'https://vitepress.dev/' } ] ,
84- [ 'script' , { src : 'https://cdn.usefathom.com/script.js' , 'data-site' : 'AZBRSFGG' , 'data-spa' : 'auto' , defer : '' } ]
85- ] ,
108+ themeConfig : {
109+ logo : { src : '/vitepress-logo-mini.svg' , width : 24 , height : 24 } ,
86110
87- themeConfig : {
88- logo : { src : '/vitepress-logo-mini.svg' , width : 24 , height : 24 } ,
111+ socialLinks : [
112+ { icon : 'github' , link : 'https://github.com/vuejs/vitepress' }
113+ ] ,
89114
90- socialLinks : [
91- { icon : 'github' , link : 'https://github.com/vuejs/vitepress' }
92- ] ,
115+ search : {
116+ provider : 'algolia' ,
117+ options : {
118+ appId : '8J64VVRP8K' ,
119+ apiKey : '52f578a92b88ad6abde815aae2b0ad7c' ,
120+ indexName : 'vitepress'
121+ }
122+ } ,
93123
94- search : {
95- provider : 'algolia' ,
96- options : {
97- appId : '8J64VVRP8K' ,
98- apiKey : '52f578a92b88ad6abde815aae2b0ad7c' ,
99- indexName : 'vitepress'
100- }
124+ carbonAds : { code : 'CEBDT27Y' , placement : 'vuejsorg' }
101125 } ,
102126
103- carbonAds : { code : 'CEBDT27Y' , placement : 'vuejsorg' }
104- } ,
127+ locales : {
128+ root : { label : 'English' } ,
129+ zh : { label : '简体中文' } ,
130+ pt : { label : 'Português' } ,
131+ ru : { label : 'Русский' } ,
132+ es : { label : 'Español' } ,
133+ ko : { label : '한국어' } ,
134+ fa : { label : 'فارسی' }
135+ } ,
105136
106- locales : {
107- root : { label : 'English' } ,
108- zh : { label : '简体中文' } ,
109- pt : { label : 'Português' } ,
110- ru : { label : 'Русский' } ,
111- es : { label : 'Español' } ,
112- ko : { label : '한국어' } ,
113- fa : { label : 'فارسی' }
114- } ,
137+ vite : {
138+ plugins : [
139+ groupIconVitePlugin ( {
140+ customIcon : {
141+ vitepress : localIconLoader (
142+ import . meta. url ,
143+ '../public/vitepress-logo-mini.svg'
144+ ) ,
145+ firebase : 'logos:firebase'
146+ }
147+ } ) ,
148+ prod &&
149+ llmstxt ( {
150+ workDir : 'en' ,
151+ ignoreFiles : [ 'index.md' ]
152+ } )
153+ ] ,
154+ experimental : {
155+ enableNativePlugin : ctx . command === 'build'
156+ }
157+ } ,
115158
116- vite : {
117- plugins : [
118- groupIconVitePlugin ( {
119- customIcon : {
120- vitepress : localIconLoader (
121- import . meta. url ,
122- '../public/vitepress-logo-mini.svg'
123- ) ,
124- firebase : 'logos:firebase'
159+ transformPageData : prod
160+ ? ( pageData , ctx ) => {
161+ const site = resolveSiteDataByRoute (
162+ ctx . siteConfig . site ,
163+ pageData . relativePath
164+ )
165+ const title = `${ pageData . title || site . title } | ${ pageData . description || site . description } `
166+ ; ( ( pageData . frontmatter . head ??= [ ] ) as HeadConfig [ ] ) . push (
167+ [ 'meta' , { property : 'og:locale' , content : site . lang } ] ,
168+ [ 'meta' , { property : 'og:title' , content : title } ]
169+ )
125170 }
126- } ) ,
127- prod &&
128- llmstxt ( {
129- workDir : 'en' ,
130- ignoreFiles : [ 'index.md' ]
131- } )
132- ]
133- } ,
134-
135- transformPageData : prod
136- ? ( pageData , ctx ) => {
137- const site = resolveSiteDataByRoute (
138- ctx . siteConfig . site ,
139- pageData . relativePath
140- )
141- const title = `${ pageData . title || site . title } | ${ pageData . description || site . description } `
142- ; ( ( pageData . frontmatter . head ??= [ ] ) as HeadConfig [ ] ) . push (
143- [ 'meta' , { property : 'og:locale' , content : site . lang } ] ,
144- [ 'meta' , { property : 'og:title' , content : title } ]
145- )
146- }
147- : undefined
148- } )
171+ : undefined
172+ } )
0 commit comments