This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (55 loc) · 1.56 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use strict";
let nunjucks = require("nunjucks");
let fs = require("hexo-fs");
let path = require("path");
let env = new nunjucks.Environment();
env = nunjucks.configure({ autoescape: false });
hexo.extend.generator.register("echart-tagcloud", function (site) {
if (hexo.config.tagcloud.enable) {
// 文件路径
let libPath = path.join(
path.join(
path.join(hexo.base_dir, "node_modules"),
"hexo-echarts-tagcloud"
),
"lib"
);
let echartswordcloudPath = path.join(
path.join(hexo.public_dir, "js/tagcloud"),
"echarts-wordcloud.min.js"
);
let echartsPath = path.join(
path.join(hexo.public_dir, "js/tagcloud"),
"echarts.simple.js"
);
let tagcloudPath = path.join(
path.join(hexo.public_dir, "js/tagcloud"),
"tagcloud.js"
);
// 生成文件
let tagcloud = nunjucks.compile(
fs.readFileSync(path.join(libPath, "tagcloud.js.tp")),
env
);
// 标签
let tags = [];
for (let i = 0; i < site.tags.data.length; i++) {
tags.push({
name: site.tags.data[i].name,
permalink: site.tags.data[i].permalink,
value: site.tags.data[i].posts.length,
});
}
var tk = tagcloud.render({
documentId: hexo.config.tagcloud.documentId,
tags: JSON.stringify(tags),
});
// 拷贝文件
fs.writeFile(tagcloudPath, tk);
fs.copyFile(path.join(libPath, "echarts.simple.js"), echartsPath);
fs.copyFile(
path.join(libPath, "echarts-wordcloud.min.js"),
echartswordcloudPath
);
}
});