Skip to content

Commit 64a5730

Browse files
committed
更新百度统计
1 parent 36cba31 commit 64a5730

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

src/.vuepress/config.ts

+10-33
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineUserConfig } from "vuepress";
22
import theme from "./theme.js";
33
import { searchProPlugin } from "vuepress-plugin-search-pro";
4-
// import { baiduTongjiPlugin } from "@vuepress-plume/vuepress-plugin-baidu-tongji";
4+
import { baiduTongjiPlugin } from "./plugins/baiduTongji.js";
55

66
export default defineUserConfig({
77
base: process.env.NETLIFY ? "/" : "/wiki/",
@@ -22,38 +22,15 @@ export default defineUserConfig({
2222
// 为分类和标签添加索引
2323
}),
2424

25-
/**
26-
* 百度统计
27-
* @see https://www.npmjs.com/package/@vuepress-plume/vuepress-plugin-baidu-tongji
28-
*
29-
*/
30-
// baiduTongjiPlugin({
31-
// key: "fc5b45ae006a231c1d5cff4610df7267",
32-
// // key: process.env.CONTEXT === "production" ? "fc5b45ae006a231c1d5cff4610df7267" : "", // 百度统计使用的 key
33-
// }),
34-
() => {
35-
const key =
36-
process.env.CONTEXT === "production"
37-
? "fc5b45ae006a231c1d5cff4610df7267"
38-
: "";
39-
return {
40-
name: "vuepress-plugin-baidu-tongji",
41-
extendsPage: (page) => {
42-
page.frontmatter.head = page.frontmatter.head || [];
43-
page.frontmatter.head?.push([
44-
"script",
45-
{
46-
type: "text/javascript",
47-
},
48-
"var _hmt = _hmt || []",
49-
]);
50-
page.frontmatter.head?.push([
51-
"script",
52-
{ src: `https://hm.baidu.com/hm.js?${key}` },
53-
]);
54-
},
55-
};
56-
},
25+
baiduTongjiPlugin({
26+
keys:
27+
process.env.CONTEXT !== "production"
28+
? [
29+
"fc5b45ae006a231c1d5cff4610df7267", // lin
30+
"fc904ee59939c7c2284063619b0ef533", // northword
31+
]
32+
: [],
33+
}),
5734
],
5835

5936
// Enable it with pwa

src/.vuepress/plugins/baiduTongji.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* 百度统计
3+
* @see https://www.npmjs.com/package/@vuepress-plume/vuepress-plugin-baidu-tongji
4+
*
5+
*/
6+
export function baiduTongjiPlugin(arg: { keys: string[] }) {
7+
return {
8+
name: "vuepress-plugin-baidu-tongji",
9+
extendsPage: (page) => {
10+
if (arg.keys.length == 0) {
11+
return;
12+
}
13+
page.frontmatter.head = page.frontmatter.head || [];
14+
page.frontmatter.head?.push([
15+
"script",
16+
{
17+
type: "text/javascript",
18+
},
19+
"var _hmt = _hmt || []",
20+
]);
21+
arg.keys.forEach((key) => {
22+
page.frontmatter.head?.push([
23+
"script",
24+
{ src: `https://hm.baidu.com/hm.js?${key}` },
25+
]);
26+
});
27+
},
28+
};
29+
}

0 commit comments

Comments
 (0)