mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-08-09 03:58:51 +08:00
Compare commits
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
- var pjaxExclude = 'a:not([target="_blank"])'
|
- var pjaxExclude = 'a:not([target="_blank"]):not([data-fancybox])'
|
||||||
if theme.pjax.exclude
|
if theme.pjax.exclude
|
||||||
each val in theme.pjax.exclude
|
each val in theme.pjax.exclude
|
||||||
- pjaxExclude += `:not([href="${val}"])`
|
- pjaxExclude += `:not([href="${val}"])`
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hexo-theme-butterfly",
|
"name": "hexo-theme-butterfly",
|
||||||
"version": "5.6.0",
|
"version": "5.6.1",
|
||||||
"description": "A Simple and Card UI Design theme for Hexo",
|
"description": "A Simple and Card UI Design theme for Hexo",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+18
-16
@@ -1,22 +1,24 @@
|
|||||||
'use strict'
|
'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 () {
|
hexo.extend.helper.register('groupPosts', function () {
|
||||||
const getGroupArray = array => {
|
const groups = hexo._seriesGroups || {}
|
||||||
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
|
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))
|
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
|
||||||
})
|
})
|
||||||
|
|||||||
+47
-26
@@ -10,27 +10,42 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const urlFor = require('hexo-util').url_for.bind(hexo)
|
const urlFor = require('hexo-util').url_for.bind(hexo)
|
||||||
|
|
||||||
|
// Iterate all posts once and group by series name.
|
||||||
|
// Result is stored on hexo._seriesGroups, shared by both tag and helper.
|
||||||
|
function buildSeriesGroups () {
|
||||||
const groups = {}
|
const groups = {}
|
||||||
|
const posts = hexo.model('Post').toArray()
|
||||||
hexo.extend.filter.register('before_generate', () => {
|
for (let i = 0, len = posts.length; i < len; i++) {
|
||||||
Object.keys(groups).forEach(k => delete groups[k])
|
const p = posts[i]
|
||||||
})
|
if (p.series) {
|
||||||
|
if (!groups[p.series]) groups[p.series] = []
|
||||||
hexo.extend.filter.register('before_post_render', data => {
|
groups[p.series].push({
|
||||||
if (!hexo.theme.config.series.enable) return data
|
title: p.title,
|
||||||
|
path: p.path,
|
||||||
const { layout, series } = data
|
date: p.date.unix()
|
||||||
if (layout === 'post' && series) {
|
|
||||||
if (!groups[series]) groups[series] = []
|
|
||||||
groups[series].push({
|
|
||||||
title: data.title,
|
|
||||||
path: data.path,
|
|
||||||
date: data.date.unix()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return groups
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build once before the first render (hexo generate / hexo server initial load).
|
||||||
|
// before_generate runs after tag rendering, so we need this as a fallback.
|
||||||
|
hexo.extend.filter.register('before_post_render', data => {
|
||||||
|
if (!hexo.theme.config.series.enable) return data
|
||||||
|
if (!hexo._seriesGroups) {
|
||||||
|
hexo._seriesGroups = buildSeriesGroups()
|
||||||
|
}
|
||||||
return data
|
return data
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Rebuild after each generate cycle in hexo server to reflect latest post data.
|
||||||
|
hexo.extend.filter.register('before_generate', () => {
|
||||||
|
if (!hexo.theme.config.series.enable) return
|
||||||
|
hexo._seriesGroups = buildSeriesGroups()
|
||||||
|
})
|
||||||
|
|
||||||
function series (args) {
|
function series (args) {
|
||||||
const { series } = hexo.theme.config
|
const { series } = hexo.theme.config
|
||||||
if (!series.enable) {
|
if (!series.enable) {
|
||||||
@@ -38,24 +53,30 @@ function series (args) {
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const seriesArr = args.length ? groups[args[0]] : groups[this.series]
|
const groupName = args.length ? args[0] : this.series
|
||||||
|
|
||||||
if (!seriesArr) {
|
if (!groupName) {
|
||||||
hexo.log.warn(`There is no series named "${args[0]}"`)
|
hexo.log.warn('No series specified')
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const isAsc = (series.order || 1) === 1 // 1: asc, -1: desc
|
const groups = hexo._seriesGroups || {}
|
||||||
const isSortByTitle = series.orderBy === 'title'
|
const source = groups[groupName]
|
||||||
|
|
||||||
const compareFn = (a, b) => {
|
if (!source || !source.length) {
|
||||||
const itemA = isSortByTitle ? a.title.toUpperCase() : a.date
|
hexo.log.warn(`There is no series named "${groupName}"`)
|
||||||
const itemB = isSortByTitle ? b.title.toUpperCase() : b.date
|
return ''
|
||||||
|
|
||||||
return itemA < itemB ? (isAsc ? -1 : 1) : itemA > itemB ? (isAsc ? 1 : -1) : 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
seriesArr.sort(compareFn)
|
const isAsc = (series.order || 1) === 1
|
||||||
|
const isSortByTitle = series.orderBy === 'title'
|
||||||
|
|
||||||
|
// .slice() to copy before sorting, so we don't mutate the shared data
|
||||||
|
const seriesArr = source.slice().sort((a, b) => {
|
||||||
|
const itemA = isSortByTitle ? a.title.toUpperCase() : a.date
|
||||||
|
const itemB = isSortByTitle ? b.title.toUpperCase() : b.date
|
||||||
|
return itemA < itemB ? (isAsc ? -1 : 1) : itemA > itemB ? (isAsc ? 1 : -1) : 0
|
||||||
|
})
|
||||||
|
|
||||||
const listItems = seriesArr.map(ele =>
|
const listItems = seriesArr.map(ele =>
|
||||||
`<li><a href="${urlFor(ele.path)}" title="${ele.title}">${ele.title}</a></li>`
|
`<li><a href="${urlFor(ele.path)}" title="${ele.title}">${ele.title}</a></li>`
|
||||||
|
|||||||
Reference in New Issue
Block a user