mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-08 12:07:06 +08:00
feat: 升級一些項目依賴 feat: 重寫 README.md 和 README_CN.md,改進文檔結構和內容 feat: tags 標籤插件夜間模式調整 feat: 加按鈕懸停效果和動畫 fix: 修復右下角箭頭圖標位置沒有居中的 bug feat: 增加右下角箭頭和滾動百分比的切換效果 improvement: 優化 tags 頁標籤雲顯示效果 improvement: 整合部分js到 init.js improvement: 統一 CSS 變數使用,改進主題一致性
88 lines
2.3 KiB
JavaScript
88 lines
2.3 KiB
JavaScript
const { deepMerge } = require('hexo-util')
|
|
const path = require('path')
|
|
const fs = require('fs')
|
|
|
|
// Cache default config to avoid repeated file reads
|
|
let cachedDefaultConfig = null
|
|
|
|
/**
|
|
* Check Hexo version and configuration
|
|
*/
|
|
function checkHexoEnvironment (hexo) {
|
|
const { version, log, locals } = hexo
|
|
|
|
const [major, minor] = version.split('.').map(Number)
|
|
const requiredMajor = 5
|
|
const requiredMinor = 3
|
|
|
|
if (major < requiredMajor || (major === requiredMajor && minor < requiredMinor)) {
|
|
log.error('Please update Hexo to V5.3.0 or higher!')
|
|
log.error('請把 Hexo 升級到 V5.3.0 或更高的版本!')
|
|
process.exit(-1)
|
|
}
|
|
|
|
// Check for deprecated configuration file
|
|
if (locals.get) {
|
|
const data = locals.get('data')
|
|
if (data && data.butterfly) {
|
|
log.error("'butterfly.yml' is deprecated. Please use '_config.butterfly.yml'")
|
|
log.error("'butterfly.yml' 已經棄用,請使用 '_config.butterfly.yml'")
|
|
process.exit(-1)
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Load default configuration
|
|
*/
|
|
function loadDefaultConfig () {
|
|
if (cachedDefaultConfig) {
|
|
return cachedDefaultConfig
|
|
}
|
|
|
|
const configPath = path.join(__dirname, '../common/default_config.js')
|
|
cachedDefaultConfig = require(configPath)
|
|
return cachedDefaultConfig
|
|
}
|
|
|
|
/**
|
|
* Process comment system configuration
|
|
*/
|
|
function processCommentConfig (themeConfig) {
|
|
const { comments } = themeConfig
|
|
if (!comments || !comments.use) {
|
|
return
|
|
}
|
|
|
|
let { use } = comments
|
|
|
|
if (!Array.isArray(use)) {
|
|
use = typeof use === 'string' ? use.split(',') : [use]
|
|
}
|
|
|
|
use = use
|
|
.map(item => {
|
|
if (typeof item !== 'string') return item
|
|
return item.trim().toLowerCase().replace(/\b[a-z]/g, s => s.toUpperCase())
|
|
})
|
|
.filter(Boolean)
|
|
|
|
// Handle Disqus and Disqusjs conflict
|
|
if (use.includes('Disqus') && use.includes('Disqusjs')) {
|
|
hexo.log.warn('Disqus and Disqusjs conflict detected, keeping only the first one')
|
|
hexo.log.warn('檢測到 Disqus 和 Disqusjs 衝突,只保留第一個')
|
|
use = [use[0]]
|
|
}
|
|
|
|
themeConfig.comments.use = use
|
|
}
|
|
|
|
hexo.extend.filter.register('before_generate', () => {
|
|
checkHexoEnvironment(hexo)
|
|
|
|
const defaultConfig = loadDefaultConfig()
|
|
hexo.theme.config = deepMerge(defaultConfig, hexo.theme.config)
|
|
|
|
processCommentConfig(hexo.theme.config)
|
|
}, 1)
|