mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-18 18:33:42 +00:00
Remove warnings of deprecated Front-matter
This commit is contained in:
parent
3e8b35abf1
commit
041e94b33f
@ -1,71 +0,0 @@
|
||||
/**
|
||||
* Modify front-matter.
|
||||
*
|
||||
* Some keys are included by Hexo, please don't use them.
|
||||
* e.g. layout title date updated comments tags categories permalink keywords
|
||||
*
|
||||
* Some keys are generated by Hexo, don't use them either.
|
||||
* e.g. content excerpt more source full_source path permalink prev next raw photos link
|
||||
*/
|
||||
|
||||
/* global hexo */
|
||||
|
||||
'use strict';
|
||||
|
||||
const keys = ['toc', 'reward_settings', 'quicklink'];
|
||||
|
||||
function showWarnLog(source, variable) {
|
||||
hexo.log.warn(`front-matter: '${variable}' has deprecated, source: ${source}`);
|
||||
hexo.log.warn('see: https://github.com/theme-next/hexo-theme-next/pull/1211');
|
||||
}
|
||||
|
||||
function compatibleBeforeAssign(page) {
|
||||
if (page.quicklink === true) {
|
||||
page.quicklink = {enable: true};
|
||||
showWarnLog(page.source, 'quicklink:true');
|
||||
}
|
||||
if (page.quicklink === false) {
|
||||
page.quicklink = {enable: false};
|
||||
showWarnLog(page.source, 'quicklink:true');
|
||||
}
|
||||
}
|
||||
|
||||
function compatibleAfterAssign(page) {
|
||||
if (page.reward !== undefined) {
|
||||
page.reward_settings.enable = page.reward;
|
||||
showWarnLog(page.source, 'reward');
|
||||
}
|
||||
if (page.toc_number !== undefined) {
|
||||
page.toc.number = page.toc_number;
|
||||
showWarnLog(page.source, 'toc_number');
|
||||
}
|
||||
if (page.toc_max_depth !== undefined) {
|
||||
page.toc.max_depth = page.toc_max_depth;
|
||||
showWarnLog(page.source, 'toc_max_depth');
|
||||
}
|
||||
}
|
||||
|
||||
hexo.extend.filter.register('template_locals', locals => {
|
||||
const { page, theme } = locals;
|
||||
|
||||
compatibleBeforeAssign(page);
|
||||
|
||||
keys.forEach(key => {
|
||||
page[key] = Object.assign({}, theme[key], page[key]);
|
||||
});
|
||||
|
||||
compatibleAfterAssign(page);
|
||||
|
||||
// Set default value for toc.max_depth
|
||||
if (!page.toc.max_depth) {
|
||||
page.toc.max_depth = 6;
|
||||
}
|
||||
|
||||
// Set home or archive quicklink
|
||||
if (page.__index) {
|
||||
page.quicklink.enable = theme.quicklink.home;
|
||||
}
|
||||
if (page.archive) {
|
||||
page.quicklink.enable = theme.quicklink.archive;
|
||||
}
|
||||
});
|
||||
@ -3,10 +3,11 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const keys = ['toc', 'reward_settings', 'quicklink'];
|
||||
|
||||
hexo.extend.filter.register('template_locals', locals => {
|
||||
const { env, config } = hexo;
|
||||
const { __, theme } = locals;
|
||||
const { __, theme, page } = locals;
|
||||
const { i18n } = hexo.theme;
|
||||
// Hexo & NexT version
|
||||
locals.hexo_version = env.version;
|
||||
@ -18,9 +19,20 @@ hexo.extend.filter.register('template_locals', locals => {
|
||||
locals.description = __('description') !== 'description' ? __('description') : config.description;
|
||||
locals.languages = [...i18n.languages];
|
||||
locals.languages.splice(locals.languages.indexOf('default'), 1);
|
||||
locals.page.lang = locals.page.lang || locals.page.language;
|
||||
page.lang = page.lang || page.language;
|
||||
// Creative Commons
|
||||
locals.ccURL = 'https://creativecommons.org/' + (theme.creative_commons.license === 'zero' ? 'publicdomain/zero/1.0/' : 'licenses/' + theme.creative_commons.license + '/4.0/') + (theme.creative_commons.language || '');
|
||||
// PJAX
|
||||
locals.pjax = theme.pjax ? ' data-pjax' : '';
|
||||
// Front matter
|
||||
keys.forEach(key => {
|
||||
page[key] = { ...theme[key], ...page[key] };
|
||||
});
|
||||
// Set home or archive quicklink
|
||||
if (page.__index) {
|
||||
page.quicklink.enable = theme.quicklink.home;
|
||||
}
|
||||
if (page.archive) {
|
||||
page.quicklink.enable = theme.quicklink.archive;
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user