mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-08-08 19:48:42 +08:00
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
This commit is contained in:
+24
-22
@@ -1,22 +1,24 @@
|
||||
'use strict'
|
||||
|
||||
hexo.extend.helper.register('groupPosts', function () {
|
||||
const getGroupArray = array => {
|
||||
return array.reduce((groups, item) => {
|
||||
const key = item.series
|
||||
if (key) {
|
||||
groups[key] = groups[key] || []
|
||||
groups[key].push(item)
|
||||
}
|
||||
return groups
|
||||
}, {})
|
||||
}
|
||||
|
||||
const sortPosts = posts => {
|
||||
const { orderBy = 'date', order = 1 } = this.theme.aside.card_post_series
|
||||
if (orderBy === 'title') return posts.sort('title', order)
|
||||
return posts.sort('date', order)
|
||||
}
|
||||
|
||||
return getGroupArray(sortPosts(this.site.posts))
|
||||
})
|
||||
'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
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user