From 4227b8a91ed6c88749fdc5b98a1dc47a282c0937 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Sun, 2 Mar 2025 11:25:58 +0800 Subject: [PATCH] feat(theme): split the post `cover` field into `cover` and `coverStyle` (#512) --- docs/notes/theme/config/frontmatter/post.md | 17 +++---- docs/notes/theme/config/主题配置.md | 8 +--- docs/notes/theme/guide/博客.md | 45 +++++++++---------- .../src/client/components/Blog/VPPostItem.vue | 24 ++++++---- theme/src/client/components/VPButton.vue | 4 -- theme/src/client/components/VPFriends.vue | 1 + theme/src/node/prepare/prepareBlogData.ts | 8 +++- theme/src/shared/base.ts | 6 +-- theme/src/shared/frontmatter/post.ts | 6 ++- theme/src/shared/options/blog.ts | 4 +- theme/src/shared/page-data.ts | 5 ++- 11 files changed, 66 insertions(+), 62 deletions(-) diff --git a/docs/notes/theme/config/frontmatter/post.md b/docs/notes/theme/config/frontmatter/post.md index ac7ec15e..df909979 100644 --- a/docs/notes/theme/config/frontmatter/post.md +++ b/docs/notes/theme/config/frontmatter/post.md @@ -56,21 +56,22 @@ tags: ### cover -- 类型: `string \| BlogPostCover` +- 类型: `string` - 默认值: `''` 文章封面图。 封面图仅显示在 文章列表页。 -当传入为 `string` 时,表示 封面图链接地址。仅支持 绝对路径 以及 远程图片地址。 +仅支持 绝对路径 以及 远程图片地址。 -当传入为 `BlogPostCover` 时,表示 封面图配置。 +### coverStyle + +- 类型: `BlogPostCoverStyle` +- 默认值: `null + +封面图配置。 ```ts -interface BlogPostCover { - /** - * 封面图链接地址,只能使用 绝对路径 以及 远程图片地址 - */ - url: string +interface BlogPostCoverStyle { /** * 博客文章封面图的位置 */ diff --git a/docs/notes/theme/config/主题配置.md b/docs/notes/theme/config/主题配置.md index bde0fe2a..ded70ecd 100644 --- a/docs/notes/theme/config/主题配置.md +++ b/docs/notes/theme/config/主题配置.md @@ -162,16 +162,12 @@ interface BlogOptions { * * @default 'right' */ - postCover?: BlogPostCoverLayout | Omit + postCover?: BlogPostCoverLayout | BlogPostCoverStyle } type BlogPostCoverLayout = 'left' | 'right' | 'odd-left' | 'odd-right' | 'top' -interface BlogPostCover { - /** - * 封面图链接地址,只能使用 绝对路径 以及 远程图片地址 - */ - url: string +interface BlogPostCoverStyle { /** * 博客文章封面图的位置 */ diff --git a/docs/notes/theme/guide/博客.md b/docs/notes/theme/guide/博客.md index 10f1686c..95694fb9 100644 --- a/docs/notes/theme/guide/博客.md +++ b/docs/notes/theme/guide/博客.md @@ -128,7 +128,8 @@ tags: | tags | `string[]` | `[]` | 文章标签 | | sticky | `boolean \| number` | false | 是否置顶, 如果为数字,则数字越大,置顶越靠前 | | draft | `boolean` | false | 是否为草稿,草稿文章不会被展示 | -| cover | `string \| BlogPostCover` | `''` | 文章封面 | +| cover | `string` | `''` | 文章封面 | +| coverStyle | `BlogPostCoverStyle` | `null` | 文章封面样式 | | excerpt | `boolean \| string` | '' | 文章摘要,默认通过 `` 注释生成, 传入字符串表示自定义内容,不再从正文提取 | 除了以上的字段,你还可以使用 [通用 frontmatter 配置](../config/frontmatter/basic.md) 中的字段, @@ -214,8 +215,8 @@ cover: /images/cover.jpg # [!code ++] ```md --- title: 文章标题 -cover: # [!code ++:5] - url: /images/cover.jpg +cover: /images/cover.jpg # [!code ++:5] +coverStyle: layout: left ratio: 16:9 width: 300 @@ -228,7 +229,7 @@ cover: # [!code ++:5] @@ -238,8 +239,8 @@ cover: # [!code ++:5] ```md --- title: 文章标题 -cover: # [!code ++:6] - url: /images/cover.jpg +cover: /images/cover.jpg # [!code ++:6] +coverStyle: layout: left ratio: 16:9 width: 300 @@ -253,8 +254,8 @@ cover: # [!code ++:6] @@ -267,8 +268,8 @@ cover: # [!code ++:6] ```md --- title: 文章标题 -cover: # [!code ++:5] - url: /images/cover.jpg +cover: /images/cover.jpg # [!code ++:5] +coverStyle: layout: top ratio: 16:9 width: 300 @@ -281,8 +282,8 @@ cover: # [!code ++:5] @@ -318,11 +319,7 @@ export default defineUserConfig({ ```ts type BlogPostCoverLayout = 'left' | 'right' | 'odd-left' | 'odd-right' | 'top' -interface BlogPostCover { - /** - * 封面图链接地址,只能使用 绝对路径 以及 远程图片地址 - */ - url: string +interface BlogPostCoverStyle { /** * 博客文章封面图的位置 */ @@ -359,22 +356,22 @@ interface BlogPostCover { @@ -477,7 +474,7 @@ config: 这导致存在了重复功能的页面,为此,你需要 [主题配置 > 博客配置](../config/主题配置.md#blog) 中, **关闭自动生成博客文章列表页**: -(还可以在重新修改 分类页/标签页/归档页的链接地址) +(还可以重新修改 分类页/标签页/归档页的链接地址) ::: code-tabs @tab .vuepress/config.ts diff --git a/theme/src/client/components/Blog/VPPostItem.vue b/theme/src/client/components/Blog/VPPostItem.vue index dc06d73d..a7cc6827 100644 --- a/theme/src/client/components/Blog/VPPostItem.vue +++ b/theme/src/client/components/Blog/VPPostItem.vue @@ -1,5 +1,5 @@