🛠️ hexo scripts
This commit is contained in:
parent
1c857a0c5f
commit
0163b6bfe5
11
scripts/events/index.js
Normal file
11
scripts/events/index.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/* global hexo */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
hexo.on("generateBefore", () => {
|
||||||
|
require("./lib/merge-configs")(hexo);
|
||||||
|
});
|
||||||
|
|
||||||
|
hexo.on("generateAfter", () => {
|
||||||
|
require("./lib/hello")(hexo);
|
||||||
|
});
|
38
scripts/events/lib/hello.js
Normal file
38
scripts/events/lib/hello.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = (hexo) => {
|
||||||
|
const isZh = hexo.theme.i18n.languages[0].search(/zh-CN/i) !== -1;
|
||||||
|
if (isZh) {
|
||||||
|
hexo.log.info(`
|
||||||
|
------------------------------------------------
|
||||||
|
| |
|
||||||
|
| __ ________ _____ |
|
||||||
|
| /\\\\ \\ / / ____| __ \\ |
|
||||||
|
| / \\\\ \\_/ /| |__ | |__) | |
|
||||||
|
| / /\\ \\\\ / | __| | _ / |
|
||||||
|
| / ____ \\| | | |____| | \\ \\ |
|
||||||
|
| /_/ \\_\\_| |______|_| \\_\\ |
|
||||||
|
| |
|
||||||
|
| 感谢使用 Ayer 主题 ! |
|
||||||
|
| 文档: https://shen-yu.gitee.io/2019/ayer/ |
|
||||||
|
| |
|
||||||
|
------------------------------------------------
|
||||||
|
`);
|
||||||
|
} else {
|
||||||
|
hexo.log.info(`
|
||||||
|
----------------------------------------------------
|
||||||
|
| |
|
||||||
|
| __ ________ _____ |
|
||||||
|
| /\\\\ \\ / / ____| __ \\ |
|
||||||
|
| / \\\\ \\_/ /| |__ | |__) | |
|
||||||
|
| / /\\ \\\\ / | __| | _ / |
|
||||||
|
| / ____ \\| | | |____| | \\ \\ |
|
||||||
|
| /_/ \\_\\_| |______|_| \\_\\ |
|
||||||
|
| |
|
||||||
|
| Thank you for using Ayer theme ! |
|
||||||
|
| Docs: https://github.com/Shen-Yu/hexo-theme-ayer |
|
||||||
|
| |
|
||||||
|
----------------------------------------------------
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
};
|
28
scripts/events/lib/merge-configs.js
Normal file
28
scripts/events/lib/merge-configs.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const objUtil = require("../../utils/object");
|
||||||
|
const { isNotEmptyObject } = require("../../utils/object");
|
||||||
|
|
||||||
|
module.exports = (hexo) => {
|
||||||
|
const isZh = hexo.theme.i18n.languages[0].search(/zh-CN/i) !== -1;
|
||||||
|
|
||||||
|
if (isNotEmptyObject(hexo.config.theme_config)) {
|
||||||
|
hexo.theme.config = objUtil.merge(
|
||||||
|
{},
|
||||||
|
hexo.theme.config,
|
||||||
|
hexo.config.theme_config
|
||||||
|
);
|
||||||
|
if (isZh) {
|
||||||
|
hexo.log.info("[Ayer] 读取 _config.yml 中 theme_config 配置项覆盖配置");
|
||||||
|
} else {
|
||||||
|
hexo.log.info(
|
||||||
|
"[Ayer] Merge theme config from theme_config in _config.yml"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hexo.log.debug(
|
||||||
|
"[Ayer] Output theme config:\n",
|
||||||
|
JSON.stringify(hexo.theme.config, undefined, 2)
|
||||||
|
);
|
||||||
|
};
|
12
scripts/utils/join-path.js
Normal file
12
scripts/utils/join-path.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const joinPath = function(base, relative) {
|
||||||
|
if (relative && /^https*:\/\//.test(relative)) {
|
||||||
|
return relative;
|
||||||
|
}
|
||||||
|
return relative
|
||||||
|
? base.replace(/\/+$/, '') + '/' + relative.replace(/^\/+/, '')
|
||||||
|
: base;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = joinPath;
|
31
scripts/utils/object.js
Normal file
31
scripts/utils/object.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const isObject = (obj) => {
|
||||||
|
return obj && typeof obj === 'object' && !Array.isArray(obj);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isNotEmptyObject = (obj) => {
|
||||||
|
return obj && typeof obj === 'object' && Object.getOwnPropertyNames(obj).length !== 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const merge = (target, ...sources) => {
|
||||||
|
for (const source of sources) {
|
||||||
|
for (const key in source) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(source, key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (isObject(target[key]) && isObject(source[key])) {
|
||||||
|
merge(target[key], source[key]);
|
||||||
|
} else {
|
||||||
|
target[key] = source[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
isObject,
|
||||||
|
isNotEmptyObject,
|
||||||
|
merge
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user