forked from fletchto99/hexo-sliding-spoiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (36 loc) · 1.24 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
const fs = require('hexo-fs');
const path = require('path');
hexo.extend.tag.register('spoiler', function (args, content) {
return hexo.render.render({
text: content,
engine: "markdown"
}).then(function (result) {
return `<div class='spoiler collapsed'>
<div class='spoiler-title'>${args.join(" ")}</div>
<div class='spoiler-content'>${result}</div>
</div>`
})
}, {
ends: true,
async: true
});
hexo.extend.generator.register('spoiler_asset', () => [
{
path: 'css/spoiler.css',
data: function () {
return fs.createReadStream(path.resolve(path.resolve(__dirname, "./assets"), 'spoiler.css'));
}
},
{
path: 'js/spoiler.js',
data: function () {
return fs.createReadStream(path.resolve(path.resolve(__dirname, "./assets"), 'spoiler.js'));
}
}
]);
hexo.extend.filter.register('after_post_render', (data) => {
let link_css = `<link rel="stylesheet" href="${hexo.config.root}css/spoiler.css" type="text/css">`;
let link_js = `<script src="${hexo.config.root}js/spoiler.js" type="text/javascript" async></script>`;
data.content += link_css + link_js;
return data;
});