fix(style): move font cdn setting back to layout

so that we can set different font cdn providers per page/post.
pull/707/head
ppoffice 2020-04-12 21:06:49 -04:00
parent d0184c21bb
commit e6118c71f0
5 changed files with 6 additions and 19 deletions

View File

@ -1,13 +0,0 @@
/**
* Add resolved variables to the theme config for stylus.
*/
module.exports = function(hexo) {
hexo.extend.filter.register('template_locals', locals => {
const fontcdn = hexo.extend.helper.get('fontcdn').bind(locals);
hexo.theme.config['@fontface'] = {
default: fontcdn('Ubuntu:wght@400;600&family=Source+Code+Pro', 'css2'),
cyberpunk: fontcdn('Oxanium:wght@300;400;600&family=Roboto+Mono', 'css2')
};
return locals;
});
};

View File

@ -3,7 +3,6 @@ const logger = require('hexo-log')();
module.exports = hexo => {
logger.info('=== Registering Hexo extensions ===');
require('hexo-component-inferno/lib/hexo/filter/locals')(hexo);
require('./hexo/filter/stylus')(hexo);
require('./hexo/generator/category')(hexo);
require('hexo-component-inferno/lib/hexo/generator/assets')(hexo);
require('hexo-component-inferno/lib/hexo/generator/insight')(hexo);

View File

@ -30,7 +30,7 @@ function getPageTitle(page, siteTitle, helper) {
module.exports = class extends Component {
render() {
const { env, site, config, helper, page } = this.props;
const { url_for, cdn, iconcdn, is_post } = helper;
const { url_for, cdn, fontcdn, iconcdn, is_post } = helper;
const {
url,
meta_generator = true,
@ -49,6 +49,10 @@ module.exports = class extends Component {
} = head;
const language = page.lang || page.language || config.language;
const fontCssUrl = {
default: fontcdn('Ubuntu:wght@400;600&family=Source+Code+Pro', 'css2'),
cyberpunk: fontcdn('Oxanium:wght@300;400;600&family=Roboto+Mono', 'css2')
};
let hlTheme, images;
if (highlight && highlight.enable === false) {
@ -139,6 +143,7 @@ module.exports = class extends Component {
{favicon ? <link rel="icon" href={url_for(favicon)} /> : null}
<link rel="stylesheet" href={iconcdn()} />
{hlTheme ? <link rel="stylesheet" href={cdn('highlight.js', '9.12.0', 'styles/' + hlTheme + '.css')} /> : null}
<link rel="stylesheet" href={fontCssUrl[variant]} />
<link rel="stylesheet" href={url_for('/css/' + variant + '.css')} />
<Plugins site={site} config={config} helper={helper} page={page} head={true} />

View File

@ -1,5 +1,3 @@
@import url(hexo-config('@fontface.cyberpunk'))
$family-sans-serif ?= 'Oxanium', Ubuntu, Roboto, 'Open Sans', 'Microsoft YaHei', sans-serif
$family-code ?= 'Roboto Mono', monospace, 'Microsoft YaHei'
// shadow and radius

View File

@ -1,3 +1 @@
@import url(hexo-config('@fontface.default'))
@import 'style'