Skip to content

Commit 7f3b4b7

Browse files
eryajferyajf
authored andcommitted
feat(docs): 添加布蒜子访问统计功能并配置页面浏览量选项
1 parent ed94023 commit 7f3b4b7

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

docs/.vitepress/config.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,30 @@ const teekConfig = defineTeekConfig({
5858
tryRequest: true,
5959
tryCount: 5,
6060
tryIterationTime: 2000,
61+
siteView: true, // 是否开启首页的访问量和排名统计
62+
pageView: true, // 是否开启文章页的浏览量统计
63+
permalink: false, // 是否只统计永久链接的浏览量,如果为 false,则统计 VitePress 默认的文档目录链接
6164
},
6265
wordCount: true,
6366
readingTime: true,
67+
// // 自定义现有信息
68+
// overrideInfo: [
69+
// {
70+
// key: "lastActiveTime",
71+
// label: "活跃时间",
72+
// value: (_, currentValue) => (currentValue + "").replace("前", ""),
73+
// show: true,
74+
// },
75+
// ],
76+
// 自定义额外信息
77+
// appendInfo: [
78+
// {
79+
// key: "todayVisitCount",
80+
// label: "今日访问人数",
81+
// value: "获取中...",
82+
// show: true
83+
// },
84+
// ],
6485
},
6586

6687
vitePlugins: {
@@ -126,6 +147,30 @@ export default defineConfig({
126147
{},
127148
`typeof LA !== 'undefined' && LA.init({ id: "3LqfP8Icg0GeEvtn", ck: "3LqfP8Icg0GeEvtn", hashMode: true })`,
128149
], // 51.la
150+
[
151+
"script",
152+
{},
153+
`
154+
// 重写布蒜子回调函数以获取今日访问人数
155+
window.BusuanziCallback = window.BusuanziCallback || function() {};
156+
const originalCallback = window.BusuanziCallback;
157+
window.BusuanziCallback = function(data) {
158+
if (data && data.today && data.today.SiteUv !== undefined) {
159+
// 更新今日访问人数显示
160+
setTimeout(() => {
161+
const todayVisitElements = document.querySelectorAll('[data-key="todayVisitCount"] .value');
162+
todayVisitElements.forEach(el => {
163+
if (el) el.textContent = data.today.SiteUv + ' 人';
164+
});
165+
}, 100);
166+
}
167+
// 调用原始回调函数
168+
if (typeof originalCallback === 'function') {
169+
originalCallback.apply(this, arguments);
170+
}
171+
};
172+
`,
173+
],
129174
],
130175
markdown: {
131176
// 开启行号

0 commit comments

Comments
 (0)