Skip to content

Commit a51ad4f

Browse files
committed
feat: enhance homepage, add tsconfig, and improve comment/title display
1 parent e3fc3ed commit a51ad4f

15 files changed

Lines changed: 112 additions & 19 deletions

File tree

docs/.vitepress/theme/ArchiveYear.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useRoute, withBase } from "vitepress";
55
66
const route = useRoute();
77
8-
// 从路由 /archive/2018/ 中提取年份
8+
// 从路由中提取年份,兼容 /archive/2018/ 和 /blog/archive/2018/
99
const yearMatch = route.path.match(/\/archive\/(\d{4})\//);
1010
const year = yearMatch ? parseInt(yearMatch[1]) : null;
1111
@@ -49,9 +49,10 @@ function formatDate(d: string) {
4949

5050
<div class="months-list">
5151
<div
52-
v-for="group in postsGroupedByMonth"
52+
v-for="(group, index) in postsGroupedByMonth"
5353
:key="group.month"
5454
class="month-group"
55+
:id="index === postsGroupedByMonth.length - 1 ? 'latest' : undefined"
5556
>
5657
<h3 class="month-title">
5758
{{ group.month }} 月 ({{ group.posts.length }} 篇)

docs/.vitepress/theme/ArticleTitle.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<script setup lang="ts">
2+
import { computed } from "vue";
23
import { useData } from "vitepress";
34
45
const { frontmatter } = useData();
6+
7+
// 用 computed 保证 SPA 导航时响应式更新
8+
const shouldShow = computed(
9+
() =>
10+
frontmatter.value.title &&
11+
frontmatter.value.layout !== "home" &&
12+
!frontmatter.value.hideTitle,
13+
);
514
</script>
615

716
<template>
8-
<h1 v-if="frontmatter.title" class="article-h1">
17+
<h1 v-if="shouldShow" class="article-h1">
918
{{ frontmatter.title }}
1019
</h1>
1120
</template>

docs/.vitepress/theme/Giscus.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<script setup lang="ts">
2-
import { onMounted, watch, ref } from "vue";
2+
import { onMounted, watch, ref, computed } from "vue";
33
import { useData, useRoute } from "vitepress";
44
5-
const { isDark } = useData();
5+
const { isDark, frontmatter } = useData();
66
const route = useRoute();
77
const container = ref<HTMLElement>();
88
9+
// 首页、文章列表页、归档索引页不显示评论框
10+
const HIDE_COMMENT_PATHS = ["/blog/", "/blog/posts/", "/blog/archive/"];
11+
const shouldShow = computed(() => {
12+
if (frontmatter.value.layout === "home") return false;
13+
if (frontmatter.value.comment === false) return false;
14+
if (HIDE_COMMENT_PATHS.includes(route.path)) return false;
15+
return true;
16+
});
17+
918
const GISCUS_REPO = "fonghehe/blog";
1019
const GISCUS_REPO_ID = "MDEwOlJlcG9zaXRvcnkyMTUxOTg3MTQ=";
1120
const GISCUS_CATEGORY = "Announcements";
@@ -34,10 +43,18 @@ function loadGiscus() {
3443
container.value.appendChild(script);
3544
}
3645
37-
onMounted(loadGiscus);
46+
onMounted(() => {
47+
if (shouldShow.value) loadGiscus();
48+
});
3849
3950
// 路由切换时重新加载(SPA 导航)
40-
watch(() => route.path, loadGiscus);
51+
watch(
52+
() => route.path,
53+
() => {
54+
if (shouldShow.value) loadGiscus();
55+
else if (container.value) container.value.innerHTML = "";
56+
},
57+
);
4158
4259
// 切换深色/浅色主题时同步通知 giscus iframe
4360
watch(isDark, (dark) => {
@@ -54,7 +71,7 @@ watch(isDark, (dark) => {
5471
</script>
5572

5673
<template>
57-
<div ref="container" class="giscus-wrapper" />
74+
<div v-if="shouldShow" ref="container" class="giscus-wrapper" />
5875
</template>
5976

6077
<style scoped>

docs/archive/2018/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
comment: false
3+
---
4+
15
# 2018 年文章归档
26

37
<ArchiveYear />

docs/archive/2019/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
comment: false
3+
---
4+
15
# 2019 年文章归档
26

37
<ArchiveYear />

docs/archive/2020/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
comment: false
3+
---
4+
15
# 2020 年文章归档
26

37
<ArchiveYear />

docs/archive/2021/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
comment: false
3+
---
4+
15
# 2021 年文章归档
26

37
<ArchiveYear />

docs/archive/2022/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
comment: false
3+
---
4+
15
# 2022 年文章归档
26

37
<ArchiveYear />

docs/archive/2023/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
comment: false
3+
---
4+
15
# 2023 年文章归档
26

37
<ArchiveYear />

docs/archive/2024/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
comment: false
3+
---
4+
15
# 2024 年文章归档
26

37
<ArchiveYear />

0 commit comments

Comments
 (0)