chore: release v5.5.3

- Bump version from 5.5.3-b2 to 5.5.3 in package.json
- Update third-party dependencies:
  * algolia_search: 5.43.0 -> 5.46.0
  * docsearch: 4.3.1 -> 4.3.2
  * fancybox: 6.1.4 -> 6.1.7
  * katex: 0.16.25 -> 0.16.27
  * mermaid: 11.12.1 -> 11.12.2
  * waline: 3.7.1 -> 3.8.0

perf: optimize JavaScript performance
- Add defer attribute to script tags in pjax and prismjs
- Improve DOM content loading timing in pjax
- Optimize utilities with better throttle implementation
- Cache header positions for TOC performance
- Optimize related posts generation with Maps
- Improve archive helpers performance

fix: improve error handling and UI fixes
- Replace process.exit with proper error throwing
- Fix tooltip positioning with boundary checks
- Add btn-effects to readmode exit button
- Fix element height calculation for hidden elements
- Improve image filters in dark mode (brightness .88, contrast .95)

style: code improvements and consistency
- Refactor random cover generation with generator pattern
- Optimize data processing in helpers
- Clean up unused functions and improve code structure
- Fix Chinese translation: 页 -> 頁
This commit is contained in:
Jerry
2025-12-10 19:16:03 +08:00
Unverified
parent 4225d23cb6
commit f1397da086
17 changed files with 259 additions and 257 deletions
+27 -22
View File
@@ -5,39 +5,46 @@
'use strict'
hexo.extend.generator.register('post', locals => {
const previousIndexes = []
const imgTestReg = /\.(png|jpe?g|gif|svg|webp|avif)(\?.*)?$/i
const { post_asset_folder: postAssetFolder } = hexo.config
const { cover: { default_cover: defaultCover } } = hexo.theme.config
const getRandomCover = defaultCover => {
if (!defaultCover) return false
if (!Array.isArray(defaultCover)) return defaultCover
function * createCoverGenerator () {
if (!defaultCover) {
while (true) yield false
}
if (!Array.isArray(defaultCover)) {
while (true) yield defaultCover
}
const coverCount = defaultCover.length
if (coverCount === 1) {
return defaultCover[0]
while (true) yield defaultCover[0]
}
const maxPreviousIndexes = coverCount === 2 ? 1 : (coverCount === 3 ? 2 : 3)
const maxHistory = Math.min(3, coverCount - 1)
const history = []
let index
do {
index = Math.floor(Math.random() * coverCount)
} while (previousIndexes.includes(index) && previousIndexes.length < coverCount)
while (true) {
let index
do {
index = Math.floor(Math.random() * coverCount)
} while (history.includes(index))
previousIndexes.push(index)
if (previousIndexes.length > maxPreviousIndexes) {
previousIndexes.shift()
history.push(index)
if (history.length > maxHistory) history.shift()
yield defaultCover[index]
}
return defaultCover[index]
}
const coverGenerator = createCoverGenerator()
const handleImg = 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 (postAssetFolder) {
if (topImg && topImg.indexOf('/') === -1 && imgTestReg.test(topImg)) {
data.top_img = `${data.path}${topImg}`
}
@@ -50,10 +57,9 @@ hexo.extend.generator.register('post', locals => {
// If cover is not set, use random cover
if (!coverVal) {
const { cover: { default_cover: defaultCover } } = hexo.theme.config
const randomCover = getRandomCover(defaultCover)
const randomCover = coverGenerator.next().value
data.cover = randomCover
coverVal = randomCover // update coverVal
coverVal = randomCover
}
if (coverVal && (coverVal.indexOf('//') !== -1 || imgTestReg.test(coverVal))) {
@@ -63,7 +69,6 @@ hexo.extend.generator.register('post', locals => {
return data
}
// https://github.com/hexojs/hexo/blob/master/lib%2Fplugins%2Fgenerator%2Fpost.ts
const posts = locals.posts.sort('date').toArray()
const { length } = posts