From c6907dfe74f79f0d11318f37f57cfc80d3bbacce Mon Sep 17 00:00:00 2001
From: pengzhanbo
Date: Sun, 13 Oct 2024 15:23:50 +0800
Subject: [PATCH] feat(theme): add support for blog category expand depth,
close #271 (#275)
---
docs/notes/theme/config/主题配置.md | 29 +++++++++++
.../components/Blog/VPBlogCategories.vue | 2 +-
.../client/components/Blog/VPCategories.vue | 9 ++--
.../components/Blog/VPCategoriesGroup.vue | 50 ++++++++++++-------
theme/src/client/composables/blog-category.ts | 6 +++
theme/src/shared/blog.ts | 7 +++
6 files changed, 82 insertions(+), 21 deletions(-)
diff --git a/docs/notes/theme/config/主题配置.md b/docs/notes/theme/config/主题配置.md
index bb752c41..64643f08 100644
--- a/docs/notes/theme/config/主题配置.md
+++ b/docs/notes/theme/config/主题配置.md
@@ -96,18 +96,47 @@ interface BlogOptions {
* @default true
*/
tags?: boolean
+
+ /**
+ * 自定义标签页链接
+ *
+ * @default '/blog/tags/'
+ */
+ tagsLink?: string
+
/**
* 是否启用归档页
* @default true
*/
archives?: boolean
+ /**
+ * 自定义归档页链接
+ *
+ * @default '/blog/archives/'
+ */
+ archivesLink?: string
+
/**
* 是否启用分类页
* @default true
*/
categories?: boolean
+ /**
+ * 自定义分类页链接
+ *
+ * @default '/blog/categories/'
+ */
+ categoriesLink?: string
+
+ /**
+ * 分类页展开深度
+ *
+ * @default 'deep'
+ */
+ categoriesExpand?: number | 'deep'
+
/**
* 博客文章封面图
*
diff --git a/theme/src/client/components/Blog/VPBlogCategories.vue b/theme/src/client/components/Blog/VPBlogCategories.vue
index 30f1782a..3d4e3c02 100644
--- a/theme/src/client/components/Blog/VPBlogCategories.vue
+++ b/theme/src/client/components/Blog/VPBlogCategories.vue
@@ -18,7 +18,7 @@ const { categories } = useBlogCategory()
-
+
diff --git a/theme/src/client/components/Blog/VPCategories.vue b/theme/src/client/components/Blog/VPCategories.vue
index bdfe2406..9d1527a2 100644
--- a/theme/src/client/components/Blog/VPCategories.vue
+++ b/theme/src/client/components/Blog/VPCategories.vue
@@ -3,9 +3,12 @@ import type { BlogCategoryItem, BlogCategoryItemWithPost } from '../../composabl
import VPCategoriesGroup from '@theme/Blog/VPCategoriesGroup.vue'
import VPLink from '@theme/VPLink.vue'
-defineProps<{
+withDefaults(defineProps<{
items: (BlogCategoryItem | BlogCategoryItemWithPost)[]
-}>()
+ depth?: number
+}>(), {
+ depth: 0,
+})
@@ -19,7 +22,7 @@ defineProps<{
-
+
diff --git a/theme/src/client/components/Blog/VPCategoriesGroup.vue b/theme/src/client/components/Blog/VPCategoriesGroup.vue
index c87e43a8..d9aab471 100644
--- a/theme/src/client/components/Blog/VPCategoriesGroup.vue
+++ b/theme/src/client/components/Blog/VPCategoriesGroup.vue
@@ -1,53 +1,68 @@
-
+
-
+
{{ item.title }}
@@ -55,6 +70,7 @@ onMounted(() => {
v-if="item.items.length"
class="group"
:items="item.items"
+ :depth="depth"
/>
@@ -113,7 +129,7 @@ onMounted(() => {
}
}
-.vp-category-group.active > .group {
+.vp-category-group.expand > .group {
display: block;
}
diff --git a/theme/src/client/composables/blog-category.ts b/theme/src/client/composables/blog-category.ts
index 7eadfd1e..14ca27de 100644
--- a/theme/src/client/composables/blog-category.ts
+++ b/theme/src/client/composables/blog-category.ts
@@ -64,6 +64,12 @@ function sortCategory(items: BlogCategory): BlogCategory {
if (a.type === 'category' && b.type === 'category') {
return a.sort < b.sort ? -1 : 1
}
+ if (a.type === 'category' && b.type === 'post') {
+ return -1
+ }
+ if (a.type === 'post' && b.type === 'category') {
+ return 1
+ }
return 0
})
}
diff --git a/theme/src/shared/blog.ts b/theme/src/shared/blog.ts
index f271aa89..3a05116a 100644
--- a/theme/src/shared/blog.ts
+++ b/theme/src/shared/blog.ts
@@ -100,6 +100,13 @@ export interface PlumeThemeBlog {
*/
categoriesLink?: string
+ /**
+ * 分类页展开深度
+ *
+ * @default 'deep'
+ */
+ categoriesExpand?: number | 'deep'
+
/**
* 博客文章封面图
*