1- import  {  defineConfig  }  from  'vitepress' ; 
1+ import  {  createContentLoader ,  defineConfig  }  from  'vitepress' ; 
2+ 
3+ const  sidebar  =  [ ] ; 
4+ 
5+ let  generatePostLinkToSidebar  =  ( )  =>  { 
6+     generatePostLinkToSidebar  =  null ; 
7+     setTimeout ( ( )  =>  { 
8+         createContentLoader ( 'posts/*.md' ) . load ( ) . then ( ( data )  =>  { 
9+             const  postNav  =  { 
10+                 text : '帖子' , 
11+                 collapsed : false , 
12+                 items : [ ] , 
13+             } ; 
14+ 
15+             sidebar . push ( postNav ) ; 
16+ 
17+             for  ( const  item  of  data )  { 
18+                 postNav . items . push ( { 
19+                     text : item . frontmatter . title , 
20+                     link : item . url , 
21+                 } ) ; 
22+             } 
23+         } ) ; 
24+     } ) ; 
25+ } ; 
226
327// https://vitepress.dev/reference/site-config 
428export  default  defineConfig ( { 
@@ -11,26 +35,23 @@ export default defineConfig({
1135            lang : 'zh' , 
1236        } , 
1337    } , 
14-     themeConfig : { 
38+     themeConfig : new   Proxy ( { 
1539        // https://vitepress.dev/reference/default-theme-config 
16-         nav : [ 
17-             { text : '首页' ,  link : '/' } , 
18-             { text : '帖子' ,  link : '/posts' } , 
19-             { text : '示例' ,  link : '/markdown-examples' } , 
20-         ] , 
21- 
22-         sidebar : [ 
23-             { 
24-                 text : '示例' , 
25-                 items : [ 
26-                     { text : 'Markdown 示例' ,  link : '/markdown-examples' } , 
27-                     { text : '运行时 API 示例' ,  link : '/api-examples' } , 
28-                 ] , 
29-             } , 
30-         ] , 
40+         // nav: [ 
41+         //     {text: '首页', link: '/'}, 
42+         // ], 
43+ 
44+         sidebar, 
3145
3246        // socialLinks: [ 
3347        //   { icon: 'github', link: 'https://github.com/vuejs/vitepress' } 
3448        // ] 
35-     } , 
49+     } ,  { 
50+         get ( target ,  p ,  receiver ) 
51+         { 
52+             generatePostLinkToSidebar ?. ( ) ; 
53+ 
54+             return  target [ p ] ; 
55+         } , 
56+     } ) , 
3657} ) ; 
0 commit comments