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';
|
|
|
|
|
2024-01-19 01:05:44 +08:00
|
|
|
const path = require('path')
|
2022-10-20 21:34:54 +08:00
|
|
|
|
2024-01-19 01:05:44 +08:00
|
|
|
module.exports = ctx => {
|
2021-03-01 21:06:59 +08:00
|
|
|
|
2024-01-19 01:05:44 +08:00
|
|
|
const { cache, language_switcher } = ctx.theme.config
|
2021-02-19 23:33:19 +08:00
|
|
|
const warning = function(...args) {
|
2024-01-19 01:05:44 +08:00
|
|
|
ctx.log.warn(`Since ${args[0]} is turned on, the ${args[1]} is disabled to avoid potential hazards.`)
|
|
|
|
}
|
2021-02-19 23:33:19 +08:00
|
|
|
|
|
|
|
if (cache && cache.enable && language_switcher) {
|
2024-01-19 01:05:44 +08:00
|
|
|
warning('language_switcher', 'caching')
|
|
|
|
cache.enable = false
|
2021-02-19 23:33:19 +08:00
|
|
|
}
|
|
|
|
|
2024-01-19 01:05:44 +08:00
|
|
|
if (cache && cache.enable && ctx.config.relative_link) {
|
|
|
|
warning('caching', '`relative_link` option in Hexo `_config.yml`')
|
|
|
|
ctx.config.relative_link = false
|
2021-02-19 23:33:19 +08:00
|
|
|
}
|
2024-01-19 01:05:44 +08:00
|
|
|
// ctx.config.meta_generator = false;
|
2021-02-19 23:33:19 +08:00
|
|
|
|
|
|
|
// merge data
|
2024-01-19 01:05:44 +08:00
|
|
|
const data = ctx.locals.get('data')
|
2022-10-20 21:34:54 +08:00
|
|
|
// merge widgets
|
2024-01-19 01:05:44 +08:00
|
|
|
var widgets = ctx.render.renderSync({ path: path.join(ctx.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)) {
|
2024-01-19 01:05:44 +08:00
|
|
|
let widget = data.widgets[i]
|
2022-10-20 21:34:54 +08:00
|
|
|
if (widget == null || widget.length == 0) {
|
|
|
|
// delete
|
2024-01-19 01:05:44 +08:00
|
|
|
delete widgets[i]
|
2022-10-20 21:34:54 +08:00
|
|
|
} else {
|
|
|
|
// create
|
|
|
|
if (widgets[i] == null) {
|
2024-01-19 01:05:44 +08:00
|
|
|
widgets[i] = widget
|
2022-10-20 21:34:54 +08:00
|
|
|
} else {
|
|
|
|
// merge
|
|
|
|
for (let j of Object.keys(widget)) {
|
2024-01-19 01:05:44 +08:00
|
|
|
widgets[i][j] = widget[j]
|
2022-10-20 21:34:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-19 23:33:19 +08:00
|
|
|
}
|
|
|
|
}
|
2024-01-19 01:05:44 +08:00
|
|
|
|
|
|
|
ctx.theme.config.widgets = widgets
|
2021-02-19 23:33:19 +08:00
|
|
|
|
2021-03-22 21:40:35 +08:00
|
|
|
// default menu
|
2024-01-19 01:05:44 +08:00
|
|
|
if (ctx.theme.config.menubar == undefined) {
|
|
|
|
ctx.theme.config.menubar = {}
|
2021-03-22 21:40:35 +08:00
|
|
|
}
|
2021-02-19 23:33:19 +08:00
|
|
|
|
2024-01-19 01:05:44 +08:00
|
|
|
}
|