forked from EYHN/hexo-helper-live2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·79 lines (72 loc) · 2.29 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var fs = require('hexo-fs');
var path = require('path');
var url = require("url");
var generators = new Array();
var models = {
"Epsilon2.1": "Epsilon2.1/Epsilon2.1.model.json",
"Gantzert_Felixander": "Gantzert_Felixander/model.json",
"haru": "haru/haru.model.json",
"miku": "miku/miku.model.json",
"ni-j": "nito/ni-j.model.json",
"nico": "nito/nico.model.json",
"nito": "nito/nito.model.json",
"nipsilon": "nito/nipsilon.model.json",
"nietzsche": "nito/nietzsche.model.json",
"shizuku": "shizuku/shizuku.model.json",
"tsumiki": "tsumiki/tsumiki.model.json",
"wanko": "wanko/wanko.model.json",
"z16": "z16/z16.model.json",
"hibiki": "hibiki/hibiki.model.json",
"koharu": "koharu/koharu.model.json",
"haruto": "haruto/haruto.model.json",
"Unitychan": "Unitychan/unitychan.model.json",
"tororo": "tororo/tororo.model.json",
"hijiki": "hijiki/hijiki.model.json",
}
function registerFile(pathname, file) {
generators.push({
path: pathname,
data: function () {
return fs.createReadStream(file)
}
});
}
function registerDir(pathname, dir) {
var lsDir = fs.listDirSync(dir)
lsDir.forEach(function (file) {
registerFile(pathname + file, path.resolve(dir, file));
}, this);
}
hexo.extend.generator.register('live2d', function (locals) {
return generators;
});
registerDir('live2d/assets/', path.resolve(__dirname, './assets'));
registerFile('live2d/script.js', path.resolve(__dirname, './dist/bundle.js'))
hexo.extend.helper.register('live2d', function (config) {
var config = Object.assign(
{
model:"z16",
width: 150,
height: 300,
className: "live2d",
id: "live2dcanvas",
bottom: -20
},
config,
hexo.config.live2d
);
return `
<script type="text/javascript" src="/live2d/script.js"></script>
<canvas id="${config.id}" width="${config.width}" height="${config.height}" class="${config.className}"></canvas>
<style>
#${config.id} {
position: fixed;
right: 0px;
z-index: 999;
pointer-events: none;
bottom: ${config.bottom}px;
}
</style>
<script>loadlive2d(${JSON.stringify(config.id)} ,${JSON.stringify(url.resolve("/live2d/assets/",models[config.model]))})</script>
`
});