mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-10 21:17:07 +08:00
breaking changes: cover 的顯示優化 #1101
feature: default_cover 可配置顏色 fix: 修復使用本地搜索時,輸入特殊符號沒有顯示結果的 bug closed #1110 fix: 修復 頂部圖和 footer 配置帶有/的顏色參數時,無法顯示顏色的 bug improvement: 鼠標移動到分頁時,文章分頁按鈕增加説明文字 improvement: 文章頁的頂部圖顯示次序為 top_img > cover > default_top_img improvement: canonical 的鏈接根據配置生成 #1111
This commit is contained in:
@@ -6,40 +6,40 @@
|
||||
'use strict'
|
||||
|
||||
hexo.extend.filter.register('before_post_render', function (data) {
|
||||
const { config } = this
|
||||
if (config.post_asset_folder) {
|
||||
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/
|
||||
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/
|
||||
let randomCover
|
||||
let coverVal = data.cover
|
||||
|
||||
// Add path to top_img and cover if post_asset_folder is enabled
|
||||
if (hexo.config.post_asset_folder) {
|
||||
const topImg = data.top_img
|
||||
const cover = data.cover
|
||||
if (topImg && topImg.indexOf('/') === -1 && imgTestReg.test(topImg)) data.top_img = data.path + topImg
|
||||
if (cover && cover.indexOf('/') === -1) data.cover = data.path + cover
|
||||
if (coverVal && coverVal.indexOf('/') === -1 && imgTestReg.test(coverVal)) data.cover = data.path + coverVal
|
||||
}
|
||||
|
||||
if (data.cover === false) {
|
||||
data.randomcover = randomCover()
|
||||
return data
|
||||
const randomCoverFn = () => {
|
||||
const theme = hexo.theme.config
|
||||
if (!(theme.cover && theme.cover.default_cover)) return false
|
||||
if (!Array.isArray(theme.cover.default_cover)) return theme.cover.default_cover
|
||||
const num = Math.floor(Math.random() * theme.cover.default_cover.length)
|
||||
return theme.cover.default_cover[num]
|
||||
}
|
||||
|
||||
if (coverVal === false) return data
|
||||
|
||||
// If cover is not set, use random cover
|
||||
if (!coverVal) {
|
||||
randomCover = randomCoverFn()
|
||||
data.cover = randomCover
|
||||
coverVal = randomCover // update coverVal
|
||||
}
|
||||
|
||||
data.cover = data.cover || randomCover()
|
||||
return data
|
||||
})
|
||||
|
||||
function randomCover () {
|
||||
const theme = hexo.theme.config
|
||||
let cover
|
||||
let num
|
||||
|
||||
if (theme.cover && theme.cover.default_cover) {
|
||||
if (!Array.isArray(theme.cover.default_cover)) {
|
||||
cover = theme.cover.default_cover
|
||||
return cover
|
||||
} else {
|
||||
num = Math.floor(Math.random() * theme.cover.default_cover.length)
|
||||
cover = theme.cover.default_cover[num]
|
||||
return cover
|
||||
if (coverVal) {
|
||||
if (coverVal.indexOf('//') !== -1 || imgTestReg.test(coverVal)) {
|
||||
data.cover_type = 'img'
|
||||
return data
|
||||
}
|
||||
} else {
|
||||
cover = theme.default_top_img || 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
|
||||
return cover
|
||||
}
|
||||
}
|
||||
|
||||
return data
|
||||
})
|
||||
Reference in New Issue
Block a user