mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-08 12:07:06 +08:00
- 新增本地搜索分頁配置 (enablePagination, hitsPerPage) - 重構 Algolia 搜索邏輯,支援多索引和更好的錯誤處理 - 優化搜索 UI 樣式,包括分頁按鈕和響應式設計 - 改進搜索結果顯示,新增編號和更好的高亮處理 📦 依賴項更新: - 更新 plugins.yml 中的多個插件版本 (abcjs, algolia, aplayer 等) - 更新 package.json 版本號為 5.5.0 🎨 UI/UX 優化: - 改進側邊欄和目錄的動畫效果 - 優化樣式佈局,調整寬度百分比 - 新增說說頁面的分頁導航組件 - 改進右側邊欄按鈕樣式 🐛 錯誤處理和代碼優化: - 修復 Umami Analytics 的錯誤處理和數據驗證 - 改進懶加載圖片的正則表達式,避免匹配腳本標籤 - 移除未使用的變數和改進代碼結構 - 新增說說內容的 Markdown 渲染支援 🔧 其他改進: - 更新翻譯功能,移除箭頭函數語法以提升相容性
87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
const { deepMerge } = require('hexo-util')
|
|
const path = require('path')
|
|
|
|
// 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)
|