mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-17 18:22:33 +00:00
62 lines
1.2 KiB
JavaScript
62 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
function resolve(name, file = '') {
|
|
let dir;
|
|
try {
|
|
dir = path.dirname(require.resolve(`${name}/package.json`));
|
|
} catch (error) {
|
|
return '';
|
|
}
|
|
return `${dir}/${file}`;
|
|
}
|
|
|
|
function highlightTheme(name) {
|
|
const file = resolve('highlight.js', `styles/${name}.css`);
|
|
const css = fs.readFileSync(file).toString();
|
|
let rule = '';
|
|
let background = '';
|
|
let foreground = '';
|
|
css.replace(/\.hljs(\s+|,[^{]+)\{(.*?)\}/sg, (match, $1, content) => {
|
|
rule += content;
|
|
return match;
|
|
});
|
|
rule.split('\n').forEach(line => {
|
|
if (line.includes('background:')) background = line.split('background:')[1];
|
|
else if (line.includes('background-color:')) background = line.split('background-color:')[1];
|
|
else if (line.includes('color:')) foreground = line.split('color:')[1];
|
|
});
|
|
return {
|
|
file,
|
|
background,
|
|
foreground
|
|
};
|
|
}
|
|
|
|
const points = {
|
|
views: [
|
|
'head',
|
|
'header',
|
|
'sidebar',
|
|
'postMeta',
|
|
'postBodyEnd',
|
|
'footer',
|
|
'bodyEnd',
|
|
'comment'
|
|
],
|
|
styles: [
|
|
'variable',
|
|
'mixin',
|
|
'style'
|
|
]
|
|
};
|
|
|
|
// Required by theme-next-docs
|
|
module.exports = {
|
|
resolve,
|
|
highlightTheme,
|
|
points
|
|
};
|