Skip to content

Commit 4d2361a

Browse files
authored
feat(theme)!: add collections support (#704)
* feat(theme)!: add collection support
1 parent fae5825 commit 4d2361a

397 files changed

Lines changed: 8096 additions & 6003 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎cli/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
},
4141
"plume-deps": {
4242
"vuepress": "2.0.0-rc.24",
43-
"vue": "^3.5.21",
43+
"vue": "^3.5.22",
4444
"http-server": "^14.1.1",
45-
"typescript": "^5.9.2"
45+
"typescript": "^5.9.3"
4646
}
4747
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/**
2+
* @see https://theme-plume.vuejs.press/guide/collection/ 查看文档了解配置详情。
3+
*
4+
* Collections 配置文件,它在 `.vuepress/plume.config.{{#if useTs}}ts{{else}}js{{/if}}` 中被导入。
5+
*
6+
* 请注意,你应该先在这里配置好 Collections,然后再启动 vuepress,主题会在启动 vuepress 时,
7+
* 读取这里配置的 Collections,然后在与 Collection 相关的 Markdown 文件中,自动生成 permalink。
8+
*
9+
* collection 的 type 为 `post` 时,表示为 文档列表类型(即没有侧边导航栏,有文档列表页)
10+
* 可用于实现如 博客、专栏 等以文章列表聚合形式的文档集合 (内容相对碎片化的)
11+
*
12+
* collection 的 type 为 `doc` 时,表示为文档类型(即有侧边导航栏)
13+
* 可用于实现如 笔记、知识库、文档等以侧边导航栏形式的文档集合 (内容强关联、成体系的)
14+
* 如果发现 侧边栏没有显示,那么请检查你的配置是否正确,以及 Markdown 文件中的 permalink
15+
* 是否是以对应的 Collection 配置的 link 的前缀开头。 是否展示侧边栏是根据 页面链接 的前缀 与 `collection.link`
16+
* 的前缀是否匹配来决定。
17+
*/
18+
19+
/**
20+
* 在受支持的 IDE 中会智能提示配置项。
21+
*
22+
* - `defineCollections` 是用于定义 collection 集合的帮助函数
23+
* - `defineCollection` 是用于定义单个 collection 配置的帮助函数
24+
*
25+
* 通过 `defineCollection` 定义的 collection 配置,应该填入 `defineCollections` 中
26+
*/
27+
import { defineCollection, defineCollections } from 'vuepress-theme-plume'
28+
29+
{{#if multiLanguage}}
30+
{{#each locales}}
31+
/* =================== locale: {{ lang }} ======================= */
32+
33+
const {{ prefix }}Blog = defineCollection({
34+
// post 类型,这里用于实现 博客功能
35+
type: 'post',
36+
// 文档集合所在目录,相对于 `docs{{ path }}`
37+
dir: 'blog',
38+
// 文档标题,它将用于在页面的面包屑导航中显示
39+
title: 'Blog',
40+
// 文章列表页的链接,如果 `linkPrefix` 未定义,它也将作为 相关的文章的 permalink 的前缀
41+
link: '/blog/',
42+
// linkPrefix: '/article/', // 相关文章的链接前缀
43+
// postList: true, // 是否启用文章列表页
44+
// tags: true, // 是否启用标签页
45+
// archives: true, // 是否启用归档页
46+
// categories: true, // 是否启用分类页
47+
// postCover: 'right', // 文章封面位置
48+
// pagination: 15, // 每页显示文章数量
49+
})
50+
51+
const {{ prefix }}DemoDoc = defineCollection({
52+
// doc 类型,该类型带有侧边栏
53+
type: 'doc',
54+
// 文档集合所在目录,相对于 `docs{{ path }}`
55+
dir: 'demo',
56+
// `dir` 所指向的目录中的所有 markdown 文件,其 permalink 需要以 `linkPrefix` 配置作为前缀
57+
// 如果 前缀不一致,则无法生成侧边栏。
58+
// 所以请确保 markdown 文件的 permalink 都以 `{{ path }}` + `linkPrefix` 开头
59+
linkPrefix: '/demo',
60+
// 文档标题,它将用于在页面的面包屑导航中显示
61+
title: 'Demo',
62+
// 手动配置侧边栏结构
63+
sidebar: ['', 'foo', 'bar'],
64+
// 根据文件结构自动生成侧边栏
65+
// sidebar: 'auto',
66+
})
67+
68+
/**
69+
* 导出所有的 collections
70+
* ({{ prefix }}Blog 为博客示例,如果不需要博客功能,请删除)
71+
* ({{ prefix }}DemoDoc 为参考示例,如果不需要它,请删除)
72+
*/
73+
export const {{ prefix }}Collections = defineCollections([
74+
{{ prefix }}Blog,
75+
{{ prefix }}DemoDoc,
76+
])
77+
78+
{{/each}}
79+
{{else}}
80+
const blog = defineCollection({
81+
// post 类型,这里用于实现 博客功能
82+
type: 'post',
83+
// 文档集合所在目录,相对于 `docs{{ path }}`
84+
dir: 'blog',
85+
// 文档标题,它将用于在页面的面包屑导航中显示
86+
title: 'Blog',
87+
// 文章列表页的链接,如果 `linkPrefix` 未定义,它也将作为 相关的文章的 permalink 的前缀
88+
link: '/blog/',
89+
// linkPrefix: '/article/', // 相关文章的链接前缀
90+
// postList: true, // 是否启用文章列表页
91+
// tags: true, // 是否启用标签页
92+
// archives: true, // 是否启用归档页
93+
// categories: true, // 是否启用分类页
94+
// postCover: 'right', // 文章封面位置
95+
// pagination: 15, // 每页显示文章数量
96+
})
97+
98+
const demoDoc = defineCollection({
99+
// doc 类型,该类型带有侧边栏
100+
type: 'doc',
101+
// 文档集合所在目录,相对于 `docs{{ path }}`
102+
dir: 'demo',
103+
// `dir` 所指向的目录中的所有 markdown 文件,其 permalink 需要以 `linkPrefix` 配置作为前缀
104+
// 如果 前缀不一致,则无法生成侧边栏。
105+
// 所以请确保 markdown 文件的 permalink 都以 `linkPrefix` 开头
106+
linkPrefix: '/demo',
107+
// 文档标题,它将用于在页面的面包屑导航中显示
108+
title: 'Demo',
109+
// 手动配置侧边栏结构
110+
sidebar: ['', 'foo', 'bar'],
111+
// 根据文件结构自动生成侧边栏
112+
// sidebar: 'auto',
113+
})
114+
115+
/**
116+
* 导出所有的 collections
117+
* (blog 为博客示例,如果不需要博客功能,请删除)
118+
* (demoDoc 为参考示例,如果不需要它,请删除)
119+
*/
120+
export default defineCollection([
121+
blog,
122+
demoDoc,
123+
])
124+
{{/if}}

‎cli/templates/.vuepress/config.ts.handlebars‎

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,6 @@ export default defineUserConfig({
5454
// contributors: true,
5555
// changelog: false,
5656

57-
/**
58-
* 博客
59-
* @see https://theme-plume.vuejs.press/config/basic/#blog
60-
*/
61-
// blog: false, // 禁用博客
62-
// blog: {
63-
// postList: true, // 是否启用文章列表页
64-
// tags: true, // 是否启用标签页
65-
// archives: true, // 是否启用归档页
66-
// categories: true, // 是否启用分类页
67-
// postCover: 'right', // 文章封面位置
68-
// pagination: 15, // 每页显示文章数量
69-
// },
70-
71-
/* 博客文章页面链接前缀 */
72-
article: '/article/',
73-
7457
/**
7558
* 编译缓存,加快编译速度
7659
* @see https://theme-plume.vuejs.press/config/basic/#cache
@@ -116,9 +99,9 @@ export default defineUserConfig({
11699
// readingTime: true,
117100

118101
/**
119-
* markdown
120-
* @see https://theme-plume.vuejs.press/config/markdown/
121-
*/
102+
* markdown
103+
* @see https://theme-plume.vuejs.press/config/markdown/
104+
*/
122105
// markdown: {
123106
// abbr: true, // 启用 abbr 语法 *[label]: content
124107
// annotation: true, // 启用 annotation 语法 [+label]: content

‎cli/templates/.vuepress/navbar.ts.handlebars‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const {{prefix}}Navbar = defineNavbarConfig([
1515
{ text: '{{#if isEn}}Archives{{else}}归档{{/if}}', link: '{{ path }}blog/archives/' },
1616
{
1717
text: '{{#if isEn}}Notes{{else}}笔记{{/if}}',
18-
items: [{ text: '{{#if isEn}}Demo{{else}}示例{{/if}}', link: '{{ path }}notes/demo/README.md' }]
18+
items: [{ text: '{{#if isEn}}Demo{{else}}示例{{/if}}', link: '{{ path }}demo/README.md' }]
1919
},
2020
])
2121

@@ -28,7 +28,7 @@ export default defineNavbarConfig([
2828
{ text: '{{#if isEn}}Archives{{else}}归档{{/if}}', link: '/blog/archives/' },
2929
{
3030
text: '{{#if isEn}}Notes{{else}}笔记{{/if}}',
31-
items: [{ text: '{{#if isEn}}Demo{{else}}示例{{/if}}', link: '/notes/demo/README.md' }]
31+
items: [{ text: '{{#if isEn}}Demo{{else}}示例{{/if}}', link: '/demo/README.md' }]
3232
},
3333
])
3434
{{/if}}

‎cli/templates/.vuepress/notes.ts.handlebars‎

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

‎cli/templates/.vuepress/plume.config.ts.handlebars‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
import { defineThemeConfig } from 'vuepress-theme-plume'
1414
{{#if multiLanguage}}
15+
import { enCollections, zhCollections } from './collections'
1516
import { enNavbar, zhNavbar } from './navbar'
16-
import { enNotes, zhNotes } from './notes'
1717
{{else}}
1818
import navbar from './navbar'
19-
import notes from './notes'
19+
import collections from './collections'
2020
{{/if}}
2121

2222
/**
@@ -64,7 +64,7 @@ export default defineThemeConfig({
6464
},
6565

6666
navbar,
67-
notes,
67+
collections,
6868

6969
/**
7070
* 公告板
@@ -102,7 +102,7 @@ export default defineThemeConfig({
102102
},
103103

104104
navbar: {{ prefix }}Navbar,
105-
notes: {{ prefix }}Notes,
105+
collections: {{ prefix }}Collections,
106106

107107
/**
108108
* 公告板

cli/templates/docs/en/preview/custom-component.example.md renamed to cli/templates/docs/en/blog/preview/custom-component.example.md

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)