-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
41 lines (38 loc) · 1.2 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
const fs = require('hexo-fs');
const path = require('path');
hexo.extend.tag.register('spoiler', (args, content) =>
`<div class='spoiler collapsed'>
<div class='spoiler-title'>
${args.join(" ")}
</div>
<div class='spoiler-content'>
${
hexo.render.renderSync({
text: content,
engine: "markdown"
}) || "No content to show"
}
</div>
</div>`, {
ends: 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;
});