Skip to content

Commit 91aeedc

Browse files
committed
feat: 🚀 首页完成分类和标签功能
1 parent 2d64377 commit 91aeedc

File tree

25 files changed

+254
-95
lines changed

25 files changed

+254
-95
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"Iconify",
6767
"xlink",
6868
"qrcode",
69-
"cascader"
69+
"cascader",
70+
"vitepress"
7071
]
7172
}

docs/@pages/archivesPage.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
archivesPage: true
3+
title: 归档
4+
permalink: /archives/
5+
article: false
6+
---

docs/@pages/categoriesPage.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
categoriesPage: true
3+
title: 分类
4+
permalink: /categories/
5+
article: false
6+
layout: home
7+
---

docs/@pages/tagsPage.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
tagsPage: true
3+
title: 标签
4+
permalink: /tags/
5+
article: false
6+
layout: home
7+
---

plugins/vitepress-plugin-permalink/src/helper.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ export const DEFAULT_IGNORE_DIR = [
99
"components",
1010
"assets",
1111
".vitepress",
12-
"@pages",
1312
"node_modules",
14-
".vitepress",
15-
"_posts",
1613
"package.json",
1714
];
1815

plugins/vitepress-plugin-sidebar-resolve/src/helper.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ export const DEFAULT_IGNORE_DIR = [
1616
"components",
1717
"assets",
1818
".vitepress",
19-
"@pages",
2019
"node_modules",
21-
".vitepress",
22-
"_posts",
2320
"package.json",
2421
];
2522

plugins/vitepress-plugin-sidebar-resolve/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export default function VitePluginVitePressSidebarResolve(option: SidebarOption
3434
const { themeConfig, srcDir } = config.vitepress.site;
3535
option.base = option.base || srcDir || ".";
3636

37+
console.log(option);
38+
3739
// 自动生成结构化侧边栏
3840
const sidebar = createSidebar(option);
3941

vitepress-theme-tk/src/components/HomeBanner.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<script setup lang="ts" name="HomeBanner">
22
import { useDesign } from "../hooks";
33
import { useData } from "vitepress";
4-
import { computed, onMounted, onUnmounted, unref } from "vue";
4+
import { onMounted, onUnmounted, unref } from "vue";
55
import { useTypes } from "../hooks";
66
77
const { getPrefixClass } = useDesign();
88
const prefixClass = getPrefixClass("banner");
99
1010
const { site, frontmatter } = useData();
1111
12-
const title = computed(() => unref(frontmatter).name || unref(site).title || "");
13-
const descArray = computed(() => [...new Set(unref(frontmatter).tk?.description?.filter((v: string) => !!v))]);
12+
const title = unref(frontmatter).name || unref(site).title || "";
13+
const descArray = [...new Set(unref(frontmatter).tk?.description?.filter((v: string) => !!v))];
1414
1515
const { text, shouldAnimate, startTypes, stopTypes } = useTypes(descArray, {
1616
typesInTime: unref(frontmatter).tk?.typesInTime,

vitepress-theme-tk/src/components/HomeCategoryCard.vue

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,53 @@
11
<script setup lang="ts" name="HomeCategoryCard">
22
import { useDesign } from "../hooks";
33
import { postsSymbol } from "../configProvider";
4-
import { inject } from "vue";
4+
import { computed, inject, unref, ref, onMounted, watch } from "vue";
5+
import { isCategoriesPages } from "../configProvider.ts";
6+
import RouteLink from "./RouteLink.vue";
7+
import { useRoute, useData } from "vitepress";
58
69
const { getPrefixClass } = useDesign();
710
const prefixClass = getPrefixClass("category");
811
9-
const posts = inject(postsSymbol);
12+
const { frontmatter } = useData();
13+
const {
14+
groupCards: { categories },
15+
} = inject(postsSymbol);
16+
17+
const categorySize = unref(frontmatter).tk?.categorySize || 5;
18+
const currentCategories = computed(() => (isCategoriesPages() ? categories : categories.slice(0, categorySize)));
19+
20+
const route = useRoute();
21+
const category = ref("");
22+
23+
watch(
24+
route,
25+
() => {
26+
const c = new URL(window.location.href).searchParams.get("category");
27+
if (c != unref(category)) category.value = c;
28+
},
29+
{ immediate: true }
30+
);
1031
</script>
1132

1233
<template>
1334
<div :class="`${prefixClass} card`">
14-
<a title="全部分类" class="title">文章分类</a>
35+
<RouteLink to="/categories" :title="isCategoriesPages() ? '全部分类' : '文章分类'" class="title">
36+
{{ isCategoriesPages() ? "全部分类" : "文章分类" }}
37+
</RouteLink>
1538

1639
<div :class="`${prefixClass}-list`">
17-
<a v-for="(item, index) in posts.groupCards.categories" :key="index" :class="{ active: item.key === category }">
18-
{{ item.name }}
40+
<RouteLink
41+
v-for="(item, index) in currentCategories"
42+
:key="index"
43+
:to="`/categories?category=${encodeURIComponent(item.name)}`"
44+
:class="{ active: item.name === category }"
45+
>
46+
<span>{{ item.name }}</span>
1947
<span>{{ item.length }}</span>
20-
</a>
48+
</RouteLink>
2149

22-
<!-- <a v-if="length !== 'all' && length < posts.groupCards.categories.length" class="more">更多 ...</a> -->
50+
<RouteLink v-if="!isCategoriesPages() && categorySize < categories.length" to="/categories">更多 ...</RouteLink>
2351
</div>
2452
</div>
2553
</template>

vitepress-theme-tk/src/components/HomeInfo.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ import { useDesign } from "../hooks";
33
import HomeMyCard from "./HomeMyCard.vue";
44
import HomeCategoryCard from "./HomeCategoryCard.vue";
55
import HomeTagCard from "./HomeTagCard.vue";
6+
import { isHomePages, isCategoriesPages, isTagsPages } from "../configProvider.ts";
67
78
const { getPrefixClass } = useDesign();
89
const prefixClass = getPrefixClass("info");
910
</script>
1011

1112
<template>
1213
<div :class="prefixClass">
13-
<HomeMyCard />
14-
15-
<HomeCategoryCard />
16-
17-
<HomeTagCard />
14+
<HomeMyCard v-if="isHomePages()" />
15+
<HomeCategoryCard v-if="isHomePages() || isCategoriesPages()" />
16+
<HomeTagCard v-if="isHomePages() || isTagsPages()" />
1817
</div>
1918
</template>
2019

0 commit comments

Comments
 (0)