hexo-theme-stellar/scripts/events/lib/config.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-02-19 23:33:19 +08:00
/**
* 部分代码借鉴自 NexT:
* https://github.com/next-theme/hexo-theme-next/blob/master/scripts/events/lib/config.js
2022-10-20 21:34:54 +08:00
* Volantis:
* https://github.com/volantis-x/hexo-theme-volantis/blob/master/scripts/events/lib/cdn.js
2021-02-19 23:33:19 +08:00
*/
'use strict';
2022-10-20 21:34:54 +08:00
const path = require('path');
2021-02-19 23:33:19 +08:00
module.exports = hexo => {
2021-03-01 21:06:59 +08:00
2021-02-19 23:33:19 +08:00
const { cache, language_switcher } = hexo.theme.config;
const warning = function(...args) {
hexo.log.warn(`Since ${args[0]} is turned on, the ${args[1]} is disabled to avoid potential hazards.`);
};
if (cache && cache.enable && language_switcher) {
warning('language_switcher', 'caching');
cache.enable = false;
}
if (cache && cache.enable && hexo.config.relative_link) {
warning('caching', '`relative_link` option in Hexo `_config.yml`');
hexo.config.relative_link = false;
}
2022-10-29 17:23:32 +08:00
// hexo.config.meta_generator = false;
2021-02-19 23:33:19 +08:00
// merge data
const data = hexo.locals.get('data');
2022-10-20 21:34:54 +08:00
// merge widgets
var widgets = hexo.render.renderSync({ path: path.join(hexo.theme_dir, '_data/widgets.yml'), engine: 'yaml' });
2021-02-19 23:33:19 +08:00
if (data.widgets) {
2022-10-20 21:34:54 +08:00
for (let i of Object.keys(data.widgets)) {
let widget = data.widgets[i];
if (widget == null || widget.length == 0) {
// delete
delete widgets[i];
} else {
// create
if (widgets[i] == null) {
widgets[i] = widget;
} else {
// merge
for (let j of Object.keys(widget)) {
widgets[i][j] = widget[j];
}
}
}
2021-02-19 23:33:19 +08:00
}
}
2022-10-20 21:34:54 +08:00
if (hexo.theme.config.data == undefined) {
hexo.theme.config.data = {};
}
hexo.theme.config.data['widgets'] = widgets;
2021-02-19 23:33:19 +08:00
2021-03-22 21:40:35 +08:00
// default menu
2021-07-26 22:26:46 +08:00
if (hexo.theme.config.sidebar.menu == undefined) {
2021-03-22 21:40:35 +08:00
hexo.theme.config.sidebar.menu = [];
}
2021-02-19 23:33:19 +08:00
};