From 041e94b33fe41fe3a14be56267b68fa3592e37ce Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Sun, 14 Jun 2020 20:49:16 +0800 Subject: [PATCH] Remove warnings of deprecated Front-matter --- scripts/filters/front-matter.js | 71 --------------------------------- scripts/filters/locals.js | 16 +++++++- 2 files changed, 14 insertions(+), 73 deletions(-) delete mode 100644 scripts/filters/front-matter.js diff --git a/scripts/filters/front-matter.js b/scripts/filters/front-matter.js deleted file mode 100644 index 594faf9..0000000 --- a/scripts/filters/front-matter.js +++ /dev/null @@ -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; - } -}); diff --git a/scripts/filters/locals.js b/scripts/filters/locals.js index 7e1fd57..87c0d71 100644 --- a/scripts/filters/locals.js +++ b/scripts/filters/locals.js @@ -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; + } });