-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (35 loc) · 870 Bytes
/
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
'use strict';
const Filter = require('./lib/filter');
const Injector = require('./lib/injector');
const conf = Object.assign({
enable: false,
inject_css: true,
tag_name: 'hanla',
entry: '.hanla',
}, hexo.config.text_autospace_filter);
let entry = conf.entry;
if (entry.search(/^\.[\w-]+$/) > -1) {
conf.entry = {
name: entry.substr(1),
type: 'class',
};
} else if (entry.search(/^\#[\w-]+$/) > -1) {
conf.entry = {
name: entry.substr(1),
type: 'id',
};
} else if (entry.search(/^[\w-]+$/) > -1) {
conf.entry = {
name: entry,
type: 'tag',
};
} else {
// TODO catch error
}
const filter = new Filter(conf);
const injector = new Injector(conf);
if (conf.enable) {
if (conf.inject_css)
hexo.extend.injector.register('head_end', injector.process);
hexo.extend.filter.register('after_render:html', filter.process);
}