From 90f54096427daab4e2ef8d7a3360e041c00682aa Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Mon, 3 Jun 2024 00:52:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(theme):=20=E6=96=B0=E5=A2=9E=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=9C=89=E4=BE=A7=E8=BE=B9=E6=A0=8F=E5=B1=82?= =?UTF-8?q?=E7=BA=A7=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/notes/theme/config/frontmatter/basic.md | 16 +- docs/notes/theme/config/主题配置.md | 176 +++++++------ theme/src/client/components/PageAside.vue | 13 +- theme/src/client/components/PageAsideItem.vue | 8 +- theme/src/client/composables/aside.ts | 117 +-------- theme/src/client/composables/index.ts | 1 + theme/src/client/composables/outline.ts | 243 ++++++++++++++++++ theme/src/node/config/resolveLocaleOptions.ts | 1 + theme/src/shared/frontmatter.ts | 1 + theme/src/shared/options/locale.ts | 2 + 10 files changed, 368 insertions(+), 210 deletions(-) create mode 100644 theme/src/client/composables/outline.ts diff --git a/docs/notes/theme/config/frontmatter/basic.md b/docs/notes/theme/config/frontmatter/basic.md index 5f16c448..1779995a 100644 --- a/docs/notes/theme/config/frontmatter/basic.md +++ b/docs/notes/theme/config/frontmatter/basic.md @@ -54,7 +54,7 @@ permalink: /config/frontmatter/basic/ - 类型: `boolean` - 默认值: `true` -当前文章内的 外部链接是否显示 外部链接图标, 即 “ ” 图标 +当前文章内的 外部链接是否显示 外部链接图标。 ### backToTop @@ -77,6 +77,20 @@ permalink: /config/frontmatter/basic/ 当前文章是否 显示 右侧边栏。 +### outline + +- 类型: `false | number | [number, number] | 'deep'` +- 默认值: `[2, 3]` +- 详情: + + 要显示的标题级别。 + + 单个数字表示只显示该级别的标题。 + + 如果传递的是一个元组,第一个数字是最小级别,第二个数字是最大级别。 + + `'deep'` 与 `[2, 6]` 相同,将显示从 `

` 到 `

` 的所有标题。 + ### prev - 类型: `string | { text: string, link: string, icon?: string }` diff --git a/docs/notes/theme/config/主题配置.md b/docs/notes/theme/config/主题配置.md index b09427c1..e461269c 100644 --- a/docs/notes/theme/config/主题配置.md +++ b/docs/notes/theme/config/主题配置.md @@ -16,6 +16,79 @@ permalink: /config/basic/ 主题使用的插件默认已进行了配置,大多数情况下您不需要进行任何修改,如果需要使用到细致的定制化,请查阅 [此文档](/config/plugins/) +### hostname + +- 类型: `string` +- 默认值: `''` +- 详情: + + 部署站点域名。 + + 当 `hostname` 配置为有效域名时,主题将会生成 `sitemap` 和 `seo` 相关的内容。 + +### blog + +- 类型: `false | BlogOptions` +- 默认值: `{ link: '/blog/', include: ['**/*.md'], exclude: [] }` +- 详情: + + 博客配置。 + +```ts +interface BlogOptions { + /** + * blog list link + * + * @default '/blog/' + */ + link?: string + + /** + * 在 `blog.dir` 目录中,通过 glob string 配置包含文件 + * + * @default - ['**\*.md'] + */ + include?: string[] + + /** + * 在 `blog.dir` 目录中,通过 glob string 配置排除的文件 + * + * README.md 文件一般作为主页或者某个目录下的主页,不应该被读取为 blog文章 + * + * @default - ['.vuepress/', 'node_modules/', '{README,index}.md'] + */ + exclude?: string[] + + /** + * 分页配置 + */ + pagination?: false | { + /** + * 每页显示的文章数量 + * @default 10 + */ + perPage?: number + } + + /** + * 是否启用标签页 + * @default true + */ + tags?: boolean + /** + * 是否启用归档页 + * @default true + */ + archives?: boolean +} +``` + +### article + +- 类型: `string` +- 默认值: `/article/` +- 详情: 文章链接前缀 + ### locales - 类型: `Record` @@ -69,16 +142,6 @@ permalink: /config/basic/ - 默认值: `'Appearance'` - 详情: 导航栏中的主题切换按钮的文本。 -### hostname - -- 类型: `string` -- 默认值: `''` -- 详情: - - 部署站点域名。 - - 当 `hostname` 配置为有效域名时,主题将会生成 `sitemap` 和 `seo` 相关的内容。 - ### avatar - 类型: `PlumeThemeAvatar` @@ -162,79 +225,6 @@ export default { 允许显示在导航栏的社交链接。 该配置仅在 PC 端下有效。 -### blog - -- 类型: `false | BlogOptions` -- 默认值: `{ link: '/blog/', include: ['**/*.md'], exclude: [] }` -- 详情: - - 博客配置。 - -```ts -interface BlogOptions { - /** - * blog list link - * - * @default '/blog/' - */ - link?: string - - /** - * 在 `blog.dir` 目录中,通过 glob string 配置包含文件 - * - * @default - ['**\*.md'] - */ - include?: string[] - - /** - * 在 `blog.dir` 目录中,通过 glob string 配置排除的文件 - * - * README.md 文件一般作为主页或者某个目录下的主页,不应该被读取为 blog文章 - * - * @default - ['.vuepress/', 'node_modules/', '{README,index}.md'] - */ - exclude?: string[] - - /** - * 分页配置 - */ - pagination?: false | { - /** - * 每页显示的文章数量 - * @default 10 - */ - perPage?: number - /** - * 前一页的文本 - * @default 'Prev' - */ - prevPageText?: string - /** - * 后一页的文本 - * @default 'Next' - */ - nextPageText?: string - } - - /** - * 是否启用标签页 - * @default true - */ - tags?: boolean - /** - * 是否启用归档页 - * @default true - */ - archives?: boolean -} -``` - -### article - -- 类型: `string` -- 默认值: `/article/` -- 详情: 文章链接前缀 - ### navbar - 类型: `NavItem[]` @@ -332,12 +322,30 @@ type NavItem = string | { - 类型: `false | PlumeThemeNotesOptions` - 默认值: `{ link: '/note', dir: 'notes', notes: [] }` -- 详情: 笔记配置, 笔记中的文章默认不会出现在首页文章列表 +- 详情: + + 笔记配置, 笔记中的文章默认不会出现在首页文章列表 你可以将配置的notes 配置到 navbar中,以便浏览查看 详细配置请查看 [此文档](/config/notes/) +### outline + +- 类型: `false | number | [number, number] | 'deep'` +- 默认值: `[2, 3]` +- 详情: + + 要显示的标题级别。 + + 单个数字表示只显示该级别的标题。 + + 如果传递的是一个元组,第一个数字是最小级别,第二个数字是最大级别。 + + `'deep'` 与 `[2, 6]` 相同,将显示从 `

` 到 `

` 的所有标题。 + + 每个页面可以通过 [frontmatter outline](./frontmatter/basic.md#outline) 覆盖层级配置。 + ### selectLanguageName - 类型: `string` diff --git a/theme/src/client/components/PageAside.vue b/theme/src/client/components/PageAside.vue index 5b21fc5a..25e16901 100644 --- a/theme/src/client/components/PageAside.vue +++ b/theme/src/client/components/PageAside.vue @@ -1,16 +1,16 @@