Skip to content

Commit a5cfd67

Browse files
author
igyfhc
committed
侧栏生成posts链接
1 parent 77f4eaf commit a5cfd67

File tree

6 files changed

+42
-165
lines changed

6 files changed

+42
-165
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*
2-
!.gitignore
3-
!config.mjs
2+
!/.gitignore
3+
!/config.mjs
4+
!/theme/
Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
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
428
export 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
});

.apps/blog/docs/api-examples.md

Lines changed: 0 additions & 49 deletions
This file was deleted.

.apps/blog/docs/markdown-examples.md

Lines changed: 0 additions & 85 deletions
This file was deleted.

.apps/blog/docs/posts.data.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

.apps/blog/docs/posts.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)