-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (54 loc) · 1.83 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
/* global hexo */
'use strict';
const { readFileSync } = require('fs');
const injector = require('hexo-extend-injector2')(hexo);
// hljs
const hljsCfg = Object.assign({theme: 'default'}, hexo.config.highlight, {hljs: true});
hexo.config.highlight = hljsCfg;
const resolveHljsThemePath = name => {
if (!name) {
return undefined;
}
return require.resolve(`highlight.js/styles/${name}.css`);
};
if (hljsCfg.enable) {
require('./lib/load-css')(hexo)({
light: resolveHljsThemePath(hljsCfg.theme),
dark: resolveHljsThemePath(hljsCfg.theme_dark)
});
}
// prism
const prismCfg = Object.assign({theme: 'default'}, hexo.config.prismjs);
hexo.config.prismjs = prismCfg;
const resolvePrismThemePath = name => {
if (!name) {
return undefined;
}
if (name === 'default') {
// eslint-disable-next-line node/no-extraneous-require
return require.resolve('prismjs/themes/prism.css');
}
try {
return require.resolve(`prismjs/themes/prism-${name}.css`);
} catch (ignore) {
return require.resolve(`prism-themes/themes/prism-${name}.css`);
}
};
if (prismCfg.enable) {
require('./lib/load-css')(hexo)({
light: resolvePrismThemePath(prismCfg.theme),
dark: resolvePrismThemePath(prismCfg.theme_dark)
});
if (!prismCfg.preprocess) {
// eslint-disable-next-line node/no-extraneous-require
injector.register('js', readFileSync(require.resolve('prismjs'), 'utf-8'));
}
if (prismCfg.line_number) {
// eslint-disable-next-line node/no-extraneous-require
injector.register('style', readFileSync(require.resolve('prismjs/plugins/line-numbers/prism-line-numbers.css'), 'utf-8'));
if (!prismCfg.preprocess) {
// eslint-disable-next-line node/no-extraneous-require
injector.register('js', readFileSync(require.resolve('prismjs/plugins/line-numbers/prism-line-numbers.js'), 'utf-8'));
}
}
}