-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
46 lines (42 loc) · 1.48 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
const htmlReplacer = require('./src/htmlReplacer');
const referParser = require('./src/referParser');
const { config } = hexo;
hexo.extend.tag.register('references', function (args, content) {
let reference = referParser(content)
let addStlye = ""
if(args.includes("hide")) addStlye+="display:none;"
return `<ul id='refplus' style="${addStlye}">${reference.join('')}</ul>`;
}, { ends: true });
hexo.extend.tag.register('ref', function (args) {
args = args.map(arg => `<sup class='refplus-num'><a href="#ref-${arg}">[${arg}]</a></sup>`)
return args.join('');
});
hexo.extend.filter.register('after_post_render', (data) => {
if (!(data.refplus)) return data;
data.content = htmlReplacer(data.content);
data.content += `
<style>
#refplus, #refplus li{
padding:0;
margin:0;
list-style:none;
};
</style>`
if(config?.refplus?.tippy==false) return data;
data.content += `
<script src="https://unpkg.com/@popperjs/core@2"></script>
<script src="https://unpkg.com/tippy.js@6"></script>
<script>
document.querySelectorAll(".refplus-num").forEach((ref) => {
let refid = ref.firstChild.href.replace(location.origin+location.pathname,'');
let refel = document.querySelector(refid);
let refnum = refel.dataset.num;
let ref_content = refel.innerText.replace(\`[\${refnum}]\`,'');
tippy(ref, {
content: ref_content,
});
});
</script>
`
return data
});