diff --git a/scripts/events/index.js b/scripts/events/index.js index 9f46813f75..8342196a67 100644 --- a/scripts/events/index.js +++ b/scripts/events/index.js @@ -13,7 +13,7 @@ hexo.on('generateAfter', () => { if (!hexo.theme.config.reminder) return; const https = require('https'); const path = require('path'); - const env = require(path.normalize('../../package.json')); + const { version } = require(path.normalize('../../package.json')); https.get({ hostname: 'api.github.com', port : 443, @@ -30,7 +30,7 @@ hexo.on('generateAfter', () => { res.on('end', () => { try { var latest = JSON.parse(result).tag_name.replace('v', '').split('.'); - var current = env.version.split('.'); + var current = version.split('.'); var isOutdated = false; for (var i = 0; i < Math.max(latest.length, current.length); i++) { if (!current[i] || latest[i] > current[i]) { diff --git a/scripts/events/lib/config.js b/scripts/events/lib/config.js index 4e179c8016..33dfcf2e04 100644 --- a/scripts/events/lib/config.js +++ b/scripts/events/lib/config.js @@ -1,13 +1,26 @@ 'use strict'; +function isObject(item) { + return item && typeof item === 'object' && !Array.isArray(item); +} + +function merge(target, source) { + for (const key in source) { + if (isObject(target[key]) && isObject(source[key])) { + merge(target[key], source[key]); + } else { + target[key] = source[key]; + } + } + return target; +} + module.exports = hexo => { if (!hexo.locals.get) return; 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.