Skip to content

Commit

Permalink
Replace lodash with native API (theme-next#1230)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang authored Oct 21, 2019
1 parent a92a9c5 commit 02b0c61
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions scripts/events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]) {
Expand Down
17 changes: 15 additions & 2 deletions scripts/events/lib/config.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 02b0c61

Please sign in to comment.