-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from dalecgu/forsigner/dev
Support user config by using data files 通过使用Hexo3的特性Data Files支持本地修改主题的配置
- Loading branch information
Showing
4 changed files
with
99 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
/* global hexo */ | ||
|
||
/** | ||
* Merge configs in _data/fexo.yml into hexo.theme. | ||
* Note: configs in _data/fexo.yml will override configs in hexo.theme. | ||
*/ | ||
hexo.on('generateBefore', function () { | ||
var data = hexo.locals.get('data'); | ||
data && data.fexo && assign(hexo.theme.config, data.fexo); | ||
}); | ||
|
||
// https://github.com/sindresorhus/object-assign | ||
function assign(target, source) { | ||
var from; | ||
var keys; | ||
var to = toObject(target); | ||
|
||
for (var s = 1; s < arguments.length; s++) { | ||
from = arguments[s]; | ||
keys = ownEnumerableKeys(Object(from)); | ||
|
||
for (var i = 0; i < keys.length; i++) { | ||
to[keys[i]] = from[keys[i]]; | ||
} | ||
} | ||
|
||
return to; | ||
} | ||
|
||
function toObject(val) { | ||
if (val == null) { | ||
throw new TypeError('Object.assign cannot be called with null or undefined'); | ||
} | ||
|
||
return Object(val); | ||
} | ||
|
||
function ownEnumerableKeys(obj) { | ||
var keys = Object.getOwnPropertyNames(obj); | ||
|
||
if (Object.getOwnPropertySymbols) { | ||
keys = keys.concat(Object.getOwnPropertySymbols(obj)); | ||
} | ||
|
||
return keys.filter(function (key) { | ||
return Object.prototype.propertyIsEnumerable.call(obj, key); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters