mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2025-09-15 12:58:48 +08:00
feat: gallery 標簽外掛增加圖片懶加載,增加 lazyload rowHeight 和 limit 屬性配置 feat: 可設置固定導航欄 closed #1150 fix: 修復開啟懶加載後,再使用 flink_url 的方式引入友鏈數據,友鏈頭像有可能不顯示的 bug closed #1146 fix: 修復閲讀模式下,代碼塊的背景顏色仍顯示彩色背景的 bug (自定義代碼塊) closed #1139 improvement: 搜索結果換行時不會拆分單詞顯示 improvement: 優化搜索結果顯示滾動條位置 improvement: css/js 優化
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
hexo.extend.helper.register('findArchiveLength', function (func) {
|
|
const allPostsLength = this.site.posts.length
|
|
if (hexo.config.archive_generator && hexo.config.archive_generator.enable === false) return allPostsLength
|
|
const { yearly, monthly, daily } = hexo.config.archive_generator
|
|
const { year, month, day } = this.page
|
|
if (yearly === false || !year) return allPostsLength
|
|
|
|
const posts = this.site.posts.sort('date')
|
|
|
|
const compareFunc = (type, y1, m1, d1, y2, m2, d2) => {
|
|
if (type === 'year') {
|
|
return y1 === y2
|
|
} else if (type === 'month') {
|
|
return y1 === y2 && m1 === m2
|
|
} else if (type === 'day') {
|
|
return y1 === y2 && m1 === m2 && d1 === d2
|
|
}
|
|
}
|
|
|
|
const generateDateObj = (type) => {
|
|
const dateObj = []
|
|
let length = 0
|
|
|
|
posts.forEach(post => {
|
|
const date = post.date.clone()
|
|
const year = date.year()
|
|
const month = date.month() + 1
|
|
const day = date.date()
|
|
const lastData = dateObj[length - 1]
|
|
|
|
if (!lastData || !compareFunc(type, lastData.year, lastData.month, lastData.day, year, month, day)) {
|
|
const name = type === 'year' ? year : type === 'month' ? `${year}-${month}` : `${year}-${month}-${day}`
|
|
length = dateObj.push({
|
|
name,
|
|
year,
|
|
month,
|
|
day,
|
|
count: 1
|
|
})
|
|
} else {
|
|
lastData.count++
|
|
}
|
|
})
|
|
|
|
return dateObj
|
|
}
|
|
|
|
const data = func('createArchiveObj', () => {
|
|
const yearObj = yearly ? generateDateObj('year') : []
|
|
const monthObj = monthly ? generateDateObj('month') : []
|
|
const dayObj = daily ? generateDateObj('day') : []
|
|
const fullObj = [...yearObj, ...monthObj, ...dayObj]
|
|
return fullObj
|
|
})
|
|
|
|
const name = month ? day ? `${year}-${month}-${day}` : `${year}-${month}` : year
|
|
return data.find(item => item.name === name).count
|
|
})
|