-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 895 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
const { mergeWith } = require('lodash');
hexo.on('generateBefore', () => {
let config = Object.assign({
theme: 'next',
languages: 'languages'
}, hexo.config.config_plus)
let merge = (object, sources) => {
return mergeWith(object, sources, (objValue, srcValue) => {
if (Array.isArray(objValue)) {
return srcValue;
}
});
}
let data = hexo.locals.get('data') || {};
// Read config from data.next or theme_config
merge(hexo.theme.config, data[config.theme]);
// Custom languages support.
if (!data[config.languages]) {
return;
}
let mergeLang = (lang) => {
i18n.set(lang, merge(i18n.get([lang]), data[config.languages][lang]));
};
let lang = hexo.config.language;
let i18n = hexo.theme.i18n;
if (Array.isArray(lang)) {
lang.forEach(item => mergeLang(item));
} else {
mergeLang(lang);
}
});