Include additional themes for prism

This commit is contained in:
Mimi 2020-07-04 18:58:32 +08:00
parent 06812e022f
commit 2e4e1bc16f
4 changed files with 23 additions and 12 deletions

2
.github/support.yml vendored
View File

@ -8,7 +8,7 @@ supportLabel: Support
supportComment: >
:wave: @{issue-author}, we use the issue tracker exclusively for bug reports
and feature requests. However, this issue appears to be a support request.
Please use our [support channels](https://github.com/next-theme/hexo-theme-next/tree/master#feedback) to get help with the project.
Please use our [support channels](https://github.com/next-theme/hexo-theme-next#feedback) to get help with the project.
# Close issues marked as support requests
close: true

View File

@ -346,11 +346,10 @@ custom_logo: #/uploads/custom-logo.jpg
codeblock:
# Code Highlight theme
# See: https://github.com/highlightjs/highlight.js/tree/master/src/styles
# All available themes: https://theme-next.js.org/highlight/
theme:
light: default
dark: tomorrow-night
# See: https://github.com/PrismJS/prism/tree/master/themes
prism:
light: prism
dark: prism-dark
@ -817,7 +816,7 @@ motion:
enable: true
async: false
transition:
# All available Transition variants: https://theme-next.js.org/animate/
# All available transition variants: https://theme-next.js.org/animate/
post_block: fadeIn
post_header: fadeInDown
post_body: fadeInDown

View File

@ -2,14 +2,14 @@
'use strict';
hexo.on('generateBefore', () => {
hexo.extend.filter.register('before_generate', () => {
// Merge config.
require('./lib/config')(hexo);
// Add filter type `theme_inject`
require('./lib/injects')(hexo);
// Highlight
require('./lib/highlight')(hexo);
});
}, 0);
hexo.on('ready', () => {
const { version } = require('../../package.json');

View File

@ -1,6 +1,12 @@
const fs = require('fs');
const path = require('path');
function parse(file) {
function resolve(package) {
return path.dirname(require.resolve(`${package}/package.json`));
}
function highlightTheme(name) {
let file = `${resolve('highlight.js')}/styles/${name}.css`;
let css = fs.readFileSync(file).toString();
let rule = '';
let background = '';
@ -21,6 +27,12 @@ function parse(file) {
};
}
function prismTheme(name) {
let file = `${resolve('prismjs')}/themes/${name}.css`;
if (!fs.existsSync(file)) file = `${resolve('prism-themes')}/themes/${name}.css`;
return file;
}
module.exports = hexo => {
let { config } = hexo;
let theme = hexo.theme.config;
@ -28,13 +40,13 @@ module.exports = hexo => {
config.prismjs = config.prismjs || {};
theme.highlight = {
enable: config.highlight.enable && !config.prismjs.enable,
light : parse(`${hexo.plugin_dir}highlight.js/styles/${theme.codeblock.theme.light}.css`),
dark : parse(`${hexo.plugin_dir}highlight.js/styles/${theme.codeblock.theme.dark}.css`)
light : highlightTheme(theme.codeblock.theme.light),
dark : highlightTheme(theme.codeblock.theme.dark)
};
theme.prism = {
enable: config.prismjs.enable,
light : `${hexo.plugin_dir}prismjs/themes/${theme.codeblock.prism.light}.css`,
dark : `${hexo.plugin_dir}prismjs/themes/${theme.codeblock.prism.dark}.css`,
number: `${hexo.plugin_dir}prismjs/plugins/line-numbers/prism-line-numbers.css`
light : prismTheme(theme.codeblock.prism.light),
dark : prismTheme(theme.codeblock.prism.dark),
number: `${resolve('prismjs')}/plugins/line-numbers/prism-line-numbers.css`
};
};