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: > supportComment: >
:wave: @{issue-author}, we use the issue tracker exclusively for bug reports :wave: @{issue-author}, we use the issue tracker exclusively for bug reports
and feature requests. However, this issue appears to be a support request. 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 issues marked as support requests
close: true close: true

View File

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

View File

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

View File

@ -1,6 +1,12 @@
const fs = require('fs'); 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 css = fs.readFileSync(file).toString();
let rule = ''; let rule = '';
let background = ''; 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 => { module.exports = hexo => {
let { config } = hexo; let { config } = hexo;
let theme = hexo.theme.config; let theme = hexo.theme.config;
@ -28,13 +40,13 @@ module.exports = hexo => {
config.prismjs = config.prismjs || {}; config.prismjs = config.prismjs || {};
theme.highlight = { theme.highlight = {
enable: config.highlight.enable && !config.prismjs.enable, enable: config.highlight.enable && !config.prismjs.enable,
light : parse(`${hexo.plugin_dir}highlight.js/styles/${theme.codeblock.theme.light}.css`), light : highlightTheme(theme.codeblock.theme.light),
dark : parse(`${hexo.plugin_dir}highlight.js/styles/${theme.codeblock.theme.dark}.css`) dark : highlightTheme(theme.codeblock.theme.dark)
}; };
theme.prism = { theme.prism = {
enable: config.prismjs.enable, enable: config.prismjs.enable,
light : `${hexo.plugin_dir}prismjs/themes/${theme.codeblock.prism.light}.css`, light : prismTheme(theme.codeblock.prism.light),
dark : `${hexo.plugin_dir}prismjs/themes/${theme.codeblock.prism.dark}.css`, dark : prismTheme(theme.codeblock.prism.dark),
number: `${hexo.plugin_dir}prismjs/plugins/line-numbers/prism-line-numbers.css` number: `${resolve('prismjs')}/plugins/line-numbers/prism-line-numbers.css`
}; };
}; };