-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 優化 aside_archives ,改進性能和可讀性 feat: 改善 inlineImg 和 timeline 標籤的文檔,優化時間線邏輯 feat: 更新 gallery 標籤以支持額外參數,優化圖片顯示邏輯 improvement: 優化隨機封面過濾器邏輯, 避免連續重複 feat: 最新評論限制顯示 1-10 條之間 fix: artalk 的最新評論顯示待定或者封禁的評論的 bug
- Loading branch information
Showing
21 changed files
with
367 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,60 @@ | ||
/** | ||
* Butterfly | ||
* ramdom cover | ||
* Random cover for posts | ||
*/ | ||
|
||
'use strict' | ||
|
||
hexo.extend.filter.register('before_post_render', data => { | ||
const imgTestReg = /\.(png|jpe?g|gif|svg|webp|avif)(\?.*)?$/i | ||
let { cover: coverVal, top_img: topImg } = data | ||
|
||
// Add path to top_img and cover if post_asset_folder is enabled | ||
if (hexo.config.post_asset_folder) { | ||
if (topImg && topImg.indexOf('/') === -1 && imgTestReg.test(topImg)) data.top_img = `${data.path}${topImg}` | ||
if (coverVal && coverVal.indexOf('/') === -1 && imgTestReg.test(coverVal)) data.cover = `${data.path}${coverVal}` | ||
} | ||
|
||
hexo.extend.generator.register('post', locals => { | ||
const recentCovers = [] | ||
const randomCoverFn = () => { | ||
const { cover: { default_cover: defaultCover } } = hexo.theme.config | ||
if (!defaultCover) return false | ||
if (!Array.isArray(defaultCover)) return defaultCover | ||
const num = Math.floor(Math.random() * defaultCover.length) | ||
const defaultCoverLen = defaultCover.length | ||
const limit = 3 | ||
|
||
let num | ||
do { | ||
num = Math.floor(Math.random() * defaultCoverLen) | ||
} while (recentCovers.includes(num)) | ||
|
||
recentCovers.push(num) | ||
if (recentCovers.length > limit) recentCovers.shift() | ||
|
||
return defaultCover[num] | ||
} | ||
|
||
if (coverVal === false) return data | ||
const handleImg = data => { | ||
const imgTestReg = /\.(png|jpe?g|gif|svg|webp|avif)(\?.*)?$/i | ||
let { cover: coverVal, top_img: topImg } = data | ||
|
||
// If cover is not set, use random cover | ||
if (!coverVal) { | ||
const randomCover = randomCoverFn() | ||
data.cover = randomCover | ||
coverVal = randomCover // update coverVal | ||
} | ||
// Add path to top_img and cover if post_asset_folder is enabled | ||
if (hexo.config.post_asset_folder) { | ||
if (topImg && topImg.indexOf('/') === -1 && imgTestReg.test(topImg)) data.top_img = `${data.path}${topImg}` | ||
if (coverVal && coverVal.indexOf('/') === -1 && imgTestReg.test(coverVal)) data.cover = `${data.path}${coverVal}` | ||
} | ||
|
||
if (coverVal === false) return data | ||
|
||
// If cover is not set, use random cover | ||
if (!coverVal) { | ||
const randomCover = randomCoverFn() | ||
data.cover = randomCover | ||
coverVal = randomCover // update coverVal | ||
} | ||
|
||
if (coverVal && (coverVal.indexOf('//') !== -1 || imgTestReg.test(coverVal))) { | ||
data.cover_type = 'img' | ||
} | ||
|
||
if (coverVal && (coverVal.indexOf('//') !== -1 || imgTestReg.test(coverVal))) { | ||
data.cover_type = 'img' | ||
return data | ||
} | ||
|
||
return data | ||
return locals.posts.sort('date').map(post => { | ||
return { | ||
data: handleImg(post), | ||
layout: 'post', | ||
path: post.path | ||
} | ||
}) | ||
}) |
Oops, something went wrong.