@@ -28,12 +28,6 @@ const post = computed<TkContentData>(() => ({
28
28
29
29
// 站点信息数据
30
30
const docAnalysisInfo = computed (() => unref (themeRef ).docAnalysisInfo || {});
31
- // 站点信息配置项
32
- const {
33
- wordCount = true ,
34
- readingTime = true ,
35
- statistics = {},
36
- }: DocAnalysis = { ... theme .docAnalysis , ... unref (frontmatter ).docAnalysis };
37
31
38
32
// 文章阅读量、阅读时长、字数
39
33
const pageViewInfo = computed (() => {
@@ -46,39 +40,22 @@ const pageViewInfo = computed(() => {
46
40
});
47
41
48
42
// 文章信息配置项
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
+ });
50
47
51
48
// 是否展示作者、日期、分类、标签等信息
52
49
const isShowInfo = computed (() => {
53
- const arr = [showInfo ].flat ();
50
+ const arr = [unref ( articleConfig ). showInfo ].flat ();
54
51
if (arr .includes (true ) || arr .includes (" article" )) return true ;
55
52
return false ;
56
53
});
57
54
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
-
78
55
const baseInfoRef = ref <HTMLDivElement >();
79
56
80
57
const teleportInfo = () => {
81
- const { selector, position = " after" , className = " teleport" } = teleport ;
58
+ const { selector, position = " after" , className = " teleport" } = unref ( articleConfig ). teleport ;
82
59
const baseInfoRefConst = unref (baseInfoRef );
83
60
// 没有指定选择器,则不进行传送
84
61
if (! selector || ! baseInfoRefConst ) return ;
@@ -96,6 +73,35 @@ const teleportInfo = () => {
96
73
onMounted (() => {
97
74
nextTick (() => teleportInfo ());
98
75
});
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
+ });
99
105
</script >
100
106
101
107
<template >
@@ -105,18 +111,18 @@ onMounted(() => {
105
111
<div v-if =" isShowInfo" ref =" baseInfoRef" :class =" `${ns.e('wrapper')} flx-align-center`" >
106
112
<ArticleInfo :post scope =" article" />
107
113
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 >
110
116
<a title =" 文章字数" class =" hover-color" >{{ pageViewInfo.wordCount }}</a >
111
117
</div >
112
118
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 >
115
121
<a title =" 预计阅读时长" class =" hover-color" >{{ pageViewInfo.readingTime }}</a >
116
122
</div >
117
123
118
124
<div v-if =" usePageView" class =" flx-center" >
119
- <Icon ><View /></Icon >
125
+ <Icon v-if = " articleConfig.showIcon " ><View /></Icon >
120
126
<a title =" 浏览量" class =" hover-color" >{{ statisticsInfo.isGet ? statisticsInfo.pagePv : "Get..." }}</a >
121
127
</div >
122
128
</div >
0 commit comments