Files
hexo-theme-butterfly/scripts/helpers/series.js
T
myw 77ec898737 fix: exclude fancybox links from pjax and refactor series logic
- Add :not([data-fancybox]) to pjaxExclude to prevent fancybox links from being loaded via pjax
- Refactor series grouping to use a shared hexo._seriesGroups object built once
- Improve performance by avoiding repeated post iteration in both tag and helper
- Version bump to 5.6.1
2026-07-21 18:49:50 +08:00

25 lines
778 B
JavaScript

'use strict'
// Read pre-built groups from tag/series.js (hexo._seriesGroups)
// and sort each group according to the sidebar card config.
hexo.extend.helper.register('groupPosts', function () {
const groups = hexo._seriesGroups || {}
const { orderBy = 'date', order = 1 } = this.theme.aside.card_post_series
const result = {}
Object.keys(groups).forEach(key => {
const arr = groups[key].slice() // copy to avoid mutating the shared data
if (orderBy === 'title') {
arr.sort((a, b) => {
const cmp = a.title.toUpperCase().localeCompare(b.title.toUpperCase())
return order === 1 ? cmp : -cmp
})
} else {
arr.sort((a, b) => order === 1 ? a.date - b.date : b.date - a.date)
}
result[key] = arr
})
return result
})