From 94d1cbbd0e92e91c6bc605dc6dae88678d7d5b53 Mon Sep 17 00:00:00 2001 From: StevenJoeZhang <1119186082@qq.com> Date: Wed, 9 Oct 2019 15:55:56 +0800 Subject: [PATCH 1/7] Update --- scripts/events/lib/config.js | 18 +++++++----------- scripts/helpers/next-url.js | 5 +++-- scripts/tags/include-raw.js | 10 +++++----- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/scripts/events/lib/config.js b/scripts/events/lib/config.js index 0f474516fa..0ade40c96a 100644 --- a/scripts/events/lib/config.js +++ b/scripts/events/lib/config.js @@ -6,8 +6,6 @@ module.exports = hexo => { var data = hexo.locals.get('data'); if (!data) return; - const merge = require(hexo.base_dir + 'node_modules/lodash/merge'); - /** * Merge configs from _data/next.yml into hexo.theme.config. * If `override`, configs in next.yml will rewrite configs in hexo.theme.config. @@ -17,18 +15,16 @@ module.exports = hexo => { if (data.next.override) { hexo.theme.config = data.next; } else { - merge(hexo.config, data.next); - merge(hexo.theme.config, data.next); + Object.assign(hexo.config, data.next); + Object.assign(hexo.theme.config, data.next); } } else { - merge(hexo.theme.config, hexo.config.theme_config); + Object.assign(hexo.theme.config, hexo.config.theme_config); } - if (hexo.theme.config.cache && hexo.theme.config.cache.enable) { - if (hexo.config.relative_link) { - hexo.log.warn('Since caching is turned on, the `relative_link` option in Hexo `_config.yml` is set to `false` to avoid potential hazards.'); - hexo.config.relative_link = false; - } + if (hexo.theme.config.cache && hexo.theme.config.cache.enable && hexo.config.relative_link) { + hexo.log.warn('Since caching is turned on, the `relative_link` option in Hexo `_config.yml` is set to `false` to avoid potential hazards.'); + hexo.config.relative_link = false; } // Custom languages support. Introduced in NexT v6.3.0. @@ -37,7 +33,7 @@ module.exports = hexo => { var i18n = hexo.theme.i18n; var mergeLang = lang => { - i18n.set(lang, merge(i18n.get([lang]), data.languages[lang])); + i18n.set(lang, Object.assign(i18n.get([lang]), data.languages[lang])); }; if (Array.isArray(lang)) { diff --git a/scripts/helpers/next-url.js b/scripts/helpers/next-url.js index 0be848d890..95d6faca3f 100644 --- a/scripts/helpers/next-url.js +++ b/scripts/helpers/next-url.js @@ -6,10 +6,11 @@ 'use strict'; +const { htmlTag } = require('hexo-util'); +const url = require('url'); + hexo.extend.helper.register('next_url', function(path, text, options) { - var htmlTag = require('hexo-util').htmlTag; var config = this.config; - var url = require('url'); var data = url.parse(path); var siteHost = url.parse(config.url).hostname || config.url; diff --git a/scripts/tags/include-raw.js b/scripts/tags/include-raw.js index 2ef3c4a1f3..c4440fc155 100644 --- a/scripts/tags/include-raw.js +++ b/scripts/tags/include-raw.js @@ -6,18 +6,18 @@ 'use strict'; -var pathFn = require('path'); -var fs = require('hexo-fs'); +const path = require('path'); +const fs = require('hexo-fs'); function includeRaw(args) { - var path = pathFn.join(hexo.source_dir, args[0]); + var file = path.join(hexo.source_dir, args[0]); - return fs.exists(path).then(exist => { + return fs.exists(file).then(exist => { if (!exist) { hexo.log.error('Include file not found!'); return; } - return fs.readFile(path).then(contents => { + return fs.readFile(file).then(contents => { if (!contents) { hexo.log.warn('Include file empty.'); return; From 089890e7fb45a37ae7cf54a2a23b7172b22f82be Mon Sep 17 00:00:00 2001 From: StevenJoeZhang <1119186082@qq.com> Date: Thu, 10 Oct 2019 10:55:42 +0800 Subject: [PATCH 2/7] Update docs --- docs/DATA-FILES.md | 2 -- docs/ru/DATA-FILES.md | 2 -- docs/zh-CN/DATA-FILES.md | 2 -- 3 files changed, 6 deletions(-) diff --git a/docs/DATA-FILES.md b/docs/DATA-FILES.md index f4bb8d412b..7dced1ef16 100644 --- a/docs/DATA-FILES.md +++ b/docs/DATA-FILES.md @@ -8,8 +8,6 @@ At present, NexT encourages users to store some options in site's `/_config.yml` In order to resolve this issue, NexT will take advantage of Hexo [Data files](https://hexo.io/docs/data-files.html). Because Data files is introduced in Hexo 3, so you need upgrade Hexo to 3.0 (or above) to use this feature. -If you prefer Hexo 2.x, you can still use the old approach for configurations. NexT is still compatible with Hexo 2.x (but errors are possible). -

Option 1: Hexo-Way

With this way, all your configurations locate in main Hexo config file (`/_config.yml`), you don't need to touch `/themes/next/_config.yml` or create any new files. But you must preserve double spaces indents within `theme_config` option. diff --git a/docs/ru/DATA-FILES.md b/docs/ru/DATA-FILES.md index 84bdac300a..62a0e2afa1 100644 --- a/docs/ru/DATA-FILES.md +++ b/docs/ru/DATA-FILES.md @@ -8,8 +8,6 @@ Во избежании проблемы, NexT использует преимущество Hexo [дата-файлов](https://hexo.io/docs/data-files.html). И т.к. дата-файлы были представлены в Hexo 3, необходимо обновиться до Hexo 3.0 (или выше) для использования этой возможности. -Если же Вы предпочитаете Hexo 2.x, то можно использовать старый способ для конфигураций. NexT всё ещё совместим с Hexo 2.x (но возможны ошибки). -

Способ 1: Hexo-Путь

Используя этот способ, вся конфигурация будет раположена в корневом конфиге hexo (`/_config.yml`), благодаря чему нет необходимости изменять оригинальный конфиг темы (`/themes/next/_config.yml`) или создавать какие-либо новые файлы. Но в этом случае необходимо сохранять двойные отступы внутри `theme_config` параметра. diff --git a/docs/zh-CN/DATA-FILES.md b/docs/zh-CN/DATA-FILES.md index d63ae20f09..9d6608537e 100644 --- a/docs/zh-CN/DATA-FILES.md +++ b/docs/zh-CN/DATA-FILES.md @@ -8,8 +8,6 @@ 为了解决这一问题,NexT 将利用 Hexo 的[数据文件](https://hexo.io/docs/data-files.html)特性。因为数据文件是在 Hexo 3 中被引入,所以你需要更新至 Hexo 3.0 以后的版本来使用这一特性。 -如果你仍然希望使用 Hexo 2.x,你依旧可以按老的方式进行配置。NexT 仍然兼容 Hexo 2.x(但可能会出现错误)。 -

选择 1:Hexo 方式

使用这一方式,你的全部配置都将置于 Hexo 站点配置文件(`/_config.yml`),并且不需要修改 `/themes/next/_config.yml`,或者创建什么其他的文件。但是所有的主题选项必须放置在 `theme_config` 后,并全部增加两个空格的缩进。 From 90fa28dd11c4cfdd2ccb8d947280521989d957b4 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Mon, 14 Oct 2019 20:44:15 +0800 Subject: [PATCH 3/7] Update --- scripts/helpers/font.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/helpers/font.js b/scripts/helpers/font.js index 213bd280ae..a381adaa1a 100644 --- a/scripts/helpers/font.js +++ b/scripts/helpers/font.js @@ -3,27 +3,27 @@ 'use strict'; hexo.extend.helper.register('next_font', () => { - var fontConfig = hexo.theme.config.font; + var config = hexo.theme.config.font; - if (!fontConfig || !fontConfig.enable) { + if (!config || !config.enable) { return ''; } var fontDisplay = '&display=swap'; var fontSubset = '&subset=latin,latin-ext'; var fontStyles = ':300,300italic,400,400italic,700,700italic'; - var fontHost = fontConfig.host || '//fonts.googleapis.com'; + var fontHost = config.host || '//fonts.googleapis.com'; - //Get a font list from fontConfig + //Get a font list from config var fontFamilies = ['global', 'title', 'headings', 'posts', 'codes'].map(item => { - if (fontConfig[item] && fontConfig[item].family && fontConfig[item].external) { - return fontConfig[item].family + fontStyles; + if (config[item] && config[item].family && config[item].external) { + return config[item].family + fontStyles; } return ''; }); fontFamilies = fontFamilies.filter(item => item !== ''); - fontFamilies = Array.from(new Set(fontFamilies)); + fontFamilies = [...new Set(fontFamilies)]; fontFamilies = fontFamilies.join('|'); // Merge extra parameters to the final processed font string From e5d3e581c08a519aacb2a8e4e27477b5de69d7d1 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Mon, 14 Oct 2019 21:04:57 +0800 Subject: [PATCH 4/7] Update --- source/css/_variables/base.styl | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/source/css/_variables/base.styl b/source/css/_variables/base.styl index 915a825147..82c8081b65 100644 --- a/source/css/_variables/base.styl +++ b/source/css/_variables/base.styl @@ -84,8 +84,7 @@ $font-weight-bolder = 700; // Font size -$font-size-base = 1em; -$font-size-base = unit(hexo-config('font.global.size'), em) if hexo-config('font.enable') and hexo-config('font.global.size') is a 'unit'; +$font-size-base = (hexo-config('font.enable') and hexo-config('font.global.size') is a 'unit') ? unit(hexo-config('font.global.size'), em) : 1em; $font-size-smallest = .75em; $font-size-smaller = .8125em; $font-size-small = .875em; @@ -97,8 +96,7 @@ $font-size-largest = 1.375em; // Headings font size $font-size-headings-step = .125em; -$font-size-headings-base = 1.625em; -$font-size-headings-base = unit(hexo-config('font.headings.size'), em) if hexo-config('font.enable') and hexo-config('font.headings.size') is a 'unit'; +$font-size-headings-base = (hexo-config('font.enable') and hexo-config('font.headings.size') is a 'unit') ? unit(hexo-config('font.headings.size'), em) : 1.625em; // Global line height @@ -198,8 +196,7 @@ $brand-color = white; $brand-hover-color = white; $brand-bg = $black-deep; -$font-size-title = $font-size-largest; -$font-size-title = unit(hexo-config('font.title.size'), em) if hexo-config('font.enable') and hexo-config('font.title.size') is a 'unit'; +$font-size-title = (hexo-config('font.enable') and hexo-config('font.title.size') is a 'unit') ? unit(hexo-config('font.title.size'), em) : $font-size-largest; $font-size-subtitle = $font-size-smaller; $subtitle-color = $grey-dark; $site-subtitle-color = $grey-dark; @@ -215,7 +212,7 @@ $posts-collapse-margin-mobile = 20px; // Variables for sidebar section elements. // -------------------------------------------------- -$sidebar-offset = unit(hexo-config('sidebar.offset'), px) if hexo-config('sidebar.offset') is a 'unit'; +$sidebar-offset = hexo-config('sidebar.offset') is a 'unit' ? unit(hexo-config('sidebar.offset'), px) : 12px; $sidebar-nav-color = $black-light; $sidebar-nav-hover-color = $whitesmoke; $sidebar-highlight = $blue-bright; @@ -284,7 +281,7 @@ $center-quote-right = '../images/quote-r.svg'; // Note colors // -------------------------------------------------- // Read note light_bg_offset from NexT config and set in "$lbg%" to use it as string variable. -hexo-config('note.light_bg_offset') is a 'unit' ? ($lbg = unit(hexo-config('note.light_bg_offset'), "%")) : ($lbg = 0); +$lbg = hexo-config('note.light_bg_offset') is a 'unit' ? unit(hexo-config('note.light_bg_offset'), "%") : 0; // Default $note-default-border = #777; From 35cdb4fb221ac3c95f242125d0053907ec7848bd Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Mon, 14 Oct 2019 21:05:44 +0800 Subject: [PATCH 5/7] Back --- scripts/events/lib/config.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/events/lib/config.js b/scripts/events/lib/config.js index 0ade40c96a..d02120ac71 100644 --- a/scripts/events/lib/config.js +++ b/scripts/events/lib/config.js @@ -6,6 +6,8 @@ module.exports = hexo => { var data = hexo.locals.get('data'); if (!data) return; + const merge = require(hexo.base_dir + 'node_modules/lodash/merge'); + /** * Merge configs from _data/next.yml into hexo.theme.config. * If `override`, configs in next.yml will rewrite configs in hexo.theme.config. @@ -15,11 +17,11 @@ module.exports = hexo => { if (data.next.override) { hexo.theme.config = data.next; } else { - Object.assign(hexo.config, data.next); - Object.assign(hexo.theme.config, data.next); + merge(hexo.config, data.next); + merge(hexo.theme.config, data.next); } } else { - Object.assign(hexo.theme.config, hexo.config.theme_config); + merge(hexo.theme.config, hexo.config.theme_config); } if (hexo.theme.config.cache && hexo.theme.config.cache.enable && hexo.config.relative_link) { @@ -33,7 +35,7 @@ module.exports = hexo => { var i18n = hexo.theme.i18n; var mergeLang = lang => { - i18n.set(lang, Object.assign(i18n.get([lang]), data.languages[lang])); + i18n.set(lang, merge(i18n.get([lang]), data.languages[lang])); }; if (Array.isArray(lang)) { From da9f457cab35987f4c93f8190870d9082af42452 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Mon, 14 Oct 2019 23:06:30 +0800 Subject: [PATCH 6/7] json_encode -> json --- layout/_partials/head/head-unique.swig | 2 +- layout/_partials/head/head.swig | 16 ++++++++-------- layout/_scripts/pages/schedule.swig | 2 +- layout/_third-party/comments/valine.swig | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/layout/_partials/head/head-unique.swig b/layout/_partials/head/head-unique.swig index 2d831655d0..d31f460afb 100644 --- a/layout/_partials/head/head-unique.swig +++ b/layout/_partials/head/head-unique.swig @@ -10,7 +10,7 @@