Skip to content

Commit 2d20b5f

Browse files
committed
fix: 🐞 修复 frontmatter 不及时更新问题
1 parent fc49afe commit 2d20b5f

File tree

14 files changed

+116
-112
lines changed

14 files changed

+116
-112
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ pnpm plugin:build
5151

5252
## TODO
5353

54+
- permalink 重新点击菜单不重新加载,分类页、标签页每次切换进去都是重新加载,需要重新渲染数据即可
5455
- Banner 支持半图背景
5556
- 文章页添加 updateTime
5657
- 代码块 codeBlock 配置没有关闭 md 文档和样式,支持官方 [xxx] 命名
57-
- 引用 frontmatter 都支持 computed
58-
- mdH1 配置项 ignoreList 导致不生成一级标题修复
58+
- 卡片栏的 title 为函数时,额外传入 localesIndex
5959
- 新增、删除、修改 md 后自动重启,参考 Vitepress 修改 config 重启方式
6060
- 主题使用文档编写
6161
- 部署测试、线上效果测试
6262
- 发布 NPM 库
6363
- 支持无障碍
64-
- 归档页添加 commit 图标风格,如:`http://niubin.site/archive.html`
64+
- 归档页添加 commit 图标风格,如:`http://niubin.site/archive.html`

vitepress-theme-teeker/src/components/ArticleAnalyze/src/index.vue

+40-34
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ const post = computed<TkContentData>(() => ({
2828
2929
// 站点信息数据
3030
const docAnalysisInfo = computed(() => unref(themeRef).docAnalysisInfo || {});
31-
// 站点信息配置项
32-
const {
33-
wordCount = true,
34-
readingTime = true,
35-
statistics = {},
36-
}: DocAnalysis = { ...theme.docAnalysis, ...unref(frontmatter).docAnalysis };
3731
3832
// 文章阅读量、阅读时长、字数
3933
const pageViewInfo = computed(() => {
@@ -46,39 +40,22 @@ const pageViewInfo = computed(() => {
4640
});
4741
4842
// 文章信息配置项
49-
const { showInfo = true, teleport = {} }: Article = { ...theme.article, ...unref(frontmatter).article };
43+
const articleConfig = computed<Article>(() => {
44+
const { showInfo = true, showIcon = true, teleport = {} } = { ...theme.article, ...unref(frontmatter).article };
45+
return { showInfo, showIcon, teleport };
46+
});
5047
5148
// 是否展示作者、日期、分类、标签等信息
5249
const isShowInfo = computed(() => {
53-
const arr = [showInfo].flat();
50+
const arr = [unref(articleConfig).showInfo].flat();
5451
if (arr.includes(true) || arr.includes("article")) return true;
5552
return false;
5653
});
5754
58-
const route = useRoute();
59-
60-
const statisticsInfo: UseBuSunZi = {
61-
pagePv: ref(0),
62-
isGet: ref(false),
63-
};
64-
const { provider = "", pageView = true, pageIteration = 2000 }: DocAnalysis["statistics"] = statistics;
65-
const usePageView = provider === "busuanzi" && pageView;
66-
67-
if (usePageView) {
68-
// 通过不蒜子获取访问量和访客数
69-
const { pagePv, isGet, request } = useBuSunZi(true, pageIteration);
70-
statisticsInfo.pagePv = pagePv;
71-
statisticsInfo.isGet = isGet;
72-
73-
watch(route, () => {
74-
request();
75-
});
76-
}
77-
7855
const baseInfoRef = ref<HTMLDivElement>();
7956
8057
const teleportInfo = () => {
81-
const { selector, position = "after", className = "teleport" } = teleport;
58+
const { selector, position = "after", className = "teleport" } = unref(articleConfig).teleport;
8259
const baseInfoRefConst = unref(baseInfoRef);
8360
// 没有指定选择器,则不进行传送
8461
if (!selector || !baseInfoRefConst) return;
@@ -96,6 +73,35 @@ const teleportInfo = () => {
9673
onMounted(() => {
9774
nextTick(() => teleportInfo());
9875
});
76+
77+
const docAnalysisConfig = computed<DocAnalysis>(() => {
78+
const {
79+
wordCount = true,
80+
readingTime = true,
81+
statistics = {},
82+
}: DocAnalysis = { ...theme.docAnalysis, ...unref(frontmatter).docAnalysis };
83+
84+
return { wordCount, readingTime, statistics };
85+
});
86+
87+
const statisticsConfig = computed<DocAnalysis["statistics"]>(() => {
88+
const { provider = "", pageView = true, pageIteration = 2000 } = unref(docAnalysisConfig).statistics;
89+
90+
return { provider, pageView, pageIteration };
91+
});
92+
// 是否使用访问量功能
93+
const usePageView = computed(() => unref(statisticsConfig).provider && unref(statisticsConfig).pageView);
94+
95+
const statisticsInfo: UseBuSunZi = { pagePv: ref(0), isGet: ref(false) };
96+
// 通过不蒜子获取访问量
97+
const { pagePv, isGet, request } = useBuSunZi(true, unref(statisticsConfig).pageIteration);
98+
statisticsInfo.pagePv = pagePv;
99+
statisticsInfo.isGet = isGet;
100+
101+
const route = useRoute();
102+
watch(route, () => {
103+
if (unref(usePageView)) request();
104+
});
99105
</script>
100106

101107
<template>
@@ -105,18 +111,18 @@ onMounted(() => {
105111
<div v-if="isShowInfo" ref="baseInfoRef" :class="`${ns.e('wrapper')} flx-align-center`">
106112
<ArticleInfo :post scope="article" />
107113

108-
<div v-if="wordCount" class="flx-center">
109-
<Icon><Reading /></Icon>
114+
<div v-if="docAnalysisConfig.wordCount" class="flx-center">
115+
<Icon v-if="articleConfig.showIcon"><Reading /></Icon>
110116
<a title="文章字数" class="hover-color">{{ pageViewInfo.wordCount }}</a>
111117
</div>
112118

113-
<div v-if="readingTime" class="flx-center">
114-
<Icon><Clock /></Icon>
119+
<div v-if="docAnalysisConfig.readingTime" class="flx-center">
120+
<Icon v-if="articleConfig.showIcon"><Clock /></Icon>
115121
<a title="预计阅读时长" class="hover-color">{{ pageViewInfo.readingTime }}</a>
116122
</div>
117123

118124
<div v-if="usePageView" class="flx-center">
119-
<Icon><View /></Icon>
125+
<Icon v-if="articleConfig.showIcon"><View /></Icon>
120126
<a title="浏览量" class="hover-color">{{ statisticsInfo.isGet ? statisticsInfo.pagePv : "Get..." }}</a>
121127
</div>
122128
</div>

vitepress-theme-teeker/src/components/ArticleBreadcrumb/src/index.vue

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ const { theme } = useUnrefData();
1717
const { localeIndex, frontmatter, page } = useData();
1818
1919
// 面包屑配置项
20-
const breadcrumb: BreadcrumbType = {
20+
const breadcrumb = computed<BreadcrumbType>(() => ({
2121
enabled: true,
2222
showCurrentName: false,
2323
separator: "/",
2424
...theme.breadcrumb,
2525
...unref(frontmatter).breadcrumb,
26-
};
26+
}));
2727
2828
const relativePathArr = computed(() => unref(page).relativePath.split("/") || []);
2929
@@ -36,7 +36,10 @@ const breadcrumbList = computed(() => {
3636
const fileName = item.replace(/^\d+\./, "").split(".")?.[0] || "";
3737
3838
// 兼容国际化功能,如果配置多语言,在面包屑去掉多语言根目录名
39-
if ((index !== relativePathArrConst.length - 1 || breadcrumb?.showCurrentName) && fileName !== unref(localeIndex)) {
39+
if (
40+
(index !== relativePathArrConst.length - 1 || unref(breadcrumb).showCurrentName) &&
41+
fileName !== unref(localeIndex)
42+
) {
4043
classifyList.push({
4144
fileName,
4245
filePath: theme.catalogues?.inv[item]?.filePath || "",

vitepress-theme-teeker/src/components/ArticleInfo/src/index.vue

+27-17
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@ const { post, scope, split = false } = defineProps<PostBaseInfoProps>();
1919
const { theme } = useUnrefData();
2020
const { frontmatter } = useData();
2121
// 文章信息配置项
22-
const {
23-
showIcon = true,
24-
dateFormat = "yyyy-MM-dd",
25-
showAuthor = true,
26-
showDate = true,
27-
showCategory = false,
28-
showTag = false,
29-
}: Article = { ...theme.article, ...unref(frontmatter).article, ...unref(frontmatter).tk?.article };
22+
const articleConfig = computed<Article>(() => {
23+
const {
24+
showIcon = true,
25+
dateFormat = "yyyy-MM-dd",
26+
showAuthor = true,
27+
showDate = true,
28+
showCategory = false,
29+
showTag = false,
30+
}: Article = {
31+
...theme.article,
32+
...unref(frontmatter).article,
33+
...unref(frontmatter).tk?.article,
34+
};
35+
36+
return { showIcon, dateFormat, showAuthor, showDate, showCategory, showTag };
37+
});
3038
3139
const posts = usePosts();
3240
const route = useRoute();
@@ -35,17 +43,19 @@ const route = useRoute();
3543
const date = computed(() => {
3644
// 如果 date 是函数,则调用获取返回值作为 date
3745
const date = post.date;
46+
const dateFormatConst = unref(articleConfig).dateFormat;
47+
3848
if (date) {
39-
if (isFunction(dateFormat)) return dateFormat(date);
40-
return formatDate(date, dateFormat);
49+
if (isFunction(dateFormatConst)) return dateFormatConst(date);
50+
return formatDate(date, dateFormatConst);
4151
}
4252
4353
// 如果 frontmatter 没有配置 date,则从 posts 中获取文档的创建时间
4454
const originPosts: TkContentData[] = unref(posts).originPosts;
4555
const targetPost = originPosts.filter(item => [item.url, `${item.url}.md`].includes(`/${route.data.relativePath}`));
4656
47-
if (isFunction(dateFormat)) return dateFormat(targetPost[0]?.date || "");
48-
return formatDate(targetPost[0]?.date || new Date(), dateFormat);
57+
if (isFunction(dateFormatConst)) return dateFormatConst(targetPost[0]?.date || "");
58+
return formatDate(targetPost[0]?.date || new Date(), dateFormatConst);
4959
});
5060
5161
const baseInfo = computed(() => [
@@ -55,29 +65,29 @@ const baseInfo = computed(() => [
5565
data: post.author?.name,
5666
href: post.author?.link,
5767
target: post.author?.link ? "_blank" : "_self",
58-
show: showAuthor,
68+
show: unref(articleConfig).showAuthor,
5969
},
6070
{
6171
title: "创建时间",
6272
icon: Calendar,
6373
data: date,
64-
show: showDate,
74+
show: unref(articleConfig).showDate,
6575
},
6676
{
6777
title: "分类",
6878
icon: FolderOpened,
6979
dataList: post.frontmatter?.categories || [],
7080
href: "/categories?category={data}",
7181
class: "or",
72-
show: scope === "home" || showCategory,
82+
show: scope === "home" || unref(articleConfig).showCategory,
7383
},
7484
{
7585
title: "标签",
7686
icon: CollectionTag,
7787
dataList: post.frontmatter?.tags || [],
7888
href: "/tags?tag={data}",
7989
class: "or",
80-
show: scope === "home" || showTag,
90+
show: scope === "home" || unref(articleConfig).showTag,
8191
},
8292
]);
8393
</script>
@@ -89,7 +99,7 @@ const baseInfo = computed(() => [
8999
v-if="item.show && (item.data || item.dataList?.length)"
90100
:class="[ns.e('item'), `${scope}-item`, { split }]"
91101
>
92-
<Icon v-if="showIcon"><component :is="item.icon" /></Icon>
102+
<Icon v-if="articleConfig.showIcon"><component :is="item.icon" /></Icon>
93103
<a
94104
v-if="item.data"
95105
:title="item.title"

vitepress-theme-teeker/src/components/Footer/src/index.vue

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts" name="Footer">
2-
import { computed, unref } from "vue";
3-
import { withBase, useData } from "vitepress";
2+
import { computed } from "vue";
3+
import { withBase } from "vitepress";
44
import { useNamespace } from "../../../hooks";
55
import { useUnrefData } from "../../../configProvider";
66
import themeSvg from "../../../assets/svg/footerTheme";
@@ -16,13 +16,9 @@ defineOptions({ name: "Footer" });
1616
1717
const ns = useNamespace("footer");
1818
19-
const { theme } = useUnrefData();
20-
const { frontmatter } = useData();
19+
const { theme, frontmatter } = useUnrefData();
2120
22-
const { footerInfo, social = [] }: { footerInfo: FooterInfo; social: Social[] } = {
23-
...theme,
24-
...unref(frontmatter).tk,
25-
};
21+
const { footerInfo, social = [] }: { footerInfo: FooterInfo; social: Social[] } = { ...theme, ...frontmatter.tk };
2622
2723
const footerData = computed(() => {
2824
const { theme = {}, copyright = {}, icpRecord, securityRecord }: FooterInfo = footerInfo || {};

vitepress-theme-teeker/src/components/HomeBanner/src/index.vue

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts" name="HomeBanner">
2-
import { withBase, useData } from "vitepress";
2+
import { withBase } from "vitepress";
33
import { onMounted, onUnmounted, unref, ref, nextTick } from "vue";
44
import { useNamespace, useTextTypes, useSwitchData } from "../../../hooks";
55
import { useUnrefData } from "../../../configProvider";
@@ -11,9 +11,8 @@ defineOptions({ name: "HomeBanner" });
1111
1212
const ns = useNamespace("banner");
1313
14-
const { site, theme } = useUnrefData();
15-
const { frontmatter } = useData();
16-
const title = unref(frontmatter).tk?.name || site.title || "";
14+
const { site, theme, frontmatter } = useUnrefData();
15+
const title = frontmatter.tk?.name || site.title || "";
1716
1817
// Banner 配置项
1918
const {
@@ -36,11 +35,11 @@ const {
3635
typesOutTime = 100,
3736
typesNextTime = 800,
3837
typesShuffle = false,
39-
}: Banner = { ...theme.banner, ...unref(frontmatter).tk?.banner };
38+
}: Banner = { ...theme.banner, ...frontmatter.tk?.banner };
4039
const descArray: string[] = [
41-
...new Set([unref(frontmatter).tk?.description || description || []].flat()?.filter((v: string) => !!v)),
40+
...new Set([frontmatter.tk?.description || description || []].flat()?.filter((v: string) => !!v)),
4241
];
43-
const { features = [] }: Banner = { ...theme.banner, ...unref(frontmatter).tk, ...unref(frontmatter).tk?.banner };
42+
const { features = [] }: Banner = { ...theme.banner, ...frontmatter.tk, ...frontmatter.tk?.banner };
4443
4544
const isDefaultBgStyle = bgStyle === "default";
4645
const isBigImgBgStyle = bgStyle === "bigImg";

vitepress-theme-teeker/src/components/HomeCategoryCard/src/index.vue

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const ns = useNamespace("category");
1414
1515
const { categoriesPage = false } = defineProps<{ categoriesPage?: boolean }>();
1616
17-
const { theme, site } = useUnrefData();
18-
const { frontmatter, localeIndex } = useData();
17+
const { theme, site, frontmatter } = useUnrefData();
18+
const { localeIndex } = useData();
1919
2020
const route = useRoute();
2121
const pageNum = ref(1);
@@ -27,7 +27,7 @@ const {
2727
limit = 5,
2828
autoPage = false,
2929
pageSpeed = 4000,
30-
}: Category = { ...theme.category, ...unref(frontmatter).tk?.category };
30+
}: Category = { ...theme.category, ...frontmatter.tk?.category };
3131
3232
const posts = usePosts();
3333
@@ -47,13 +47,13 @@ const finalTitle = computed(() => {
4747
});
4848
4949
// 当前选中的分类,从 URL 查询参数中获取
50-
const category = ref("");
50+
const selectedCategory = ref("");
5151
5252
watch(
5353
route,
5454
() => {
5555
const c = new URL(window.location.href).searchParams.get("category");
56-
if (c && c != unref(category)) category.value = c;
56+
if (c && c != unref(selectedCategory)) selectedCategory.value = c;
5757
},
5858
{ immediate: true }
5959
);
@@ -95,7 +95,7 @@ const categoriesPageLink = computed(() => {
9595
v-for="(item, index) in currentCategories"
9696
:key="item.name"
9797
:href="withBase(`${categoriesPageLink}?category=${encodeURIComponent(item.name)}`)"
98-
:class="[{ active: item.name === category }, 'hover-color']"
98+
:class="[{ active: item.name === selectedCategory }, 'hover-color']"
9999
:style="`top: ${index * itemRefs?.[index]?.getBoundingClientRect().height || 0}px`"
100100
>
101101
<span>{{ item.name }}</span>

vitepress-theme-teeker/src/components/HomeDocAnalysisCard/src/index.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ defineOptions({ name: "HomeDocAnalysisCard" });
1212
1313
const ns = useNamespace("docAnalysis");
1414
15-
const { theme } = useUnrefData();
15+
const { theme, frontmatter } = useUnrefData();
1616
// 使用 useData 的 theme 是为了监听国际化切换来动态修改站点信息的内容
17-
const { theme: themeRef, frontmatter } = useData();
17+
const { theme: themeRef } = useData();
1818
// 站点信息配置项
1919
const {
2020
createTime,
2121
title = `${docAnalysisSvg}站点信息`,
2222
statistics = {},
2323
overrideInfo = [],
2424
appendInfo = [],
25-
}: DocAnalysis = { ...theme.docAnalysis, ...unref(frontmatter).tk?.docAnalysis };
25+
}: DocAnalysis = { ...theme.docAnalysis, ...frontmatter.tk?.docAnalysis };
2626
2727
const docAnalysisInfo = computed(() => unref(themeRef).docAnalysisInfo || {});
2828

0 commit comments

Comments
 (0)