mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 20:30:53 +08:00
breaking change: 重構 gallery 標籤外掛
improvement: 首頁社交圖標左右邊距調整 feat: 文章版權增加圖標 improvement: 重構 main.js 代碼 improvement: 優化 pjax 下的性能 fix: 修復子目錄下,pjax 跳轉 404 錯誤 feat: getScript 增加 attribute 配置 improvement: 優化手機端 toc 打開和關閉特效 improvement: 文章進入特效改為 transform, 優化 stylus improvement: 目錄側邊欄出現滾動條時,元素不會被擠壓 feat: 文章左右對齊 improvement: 處理 waline 的 url 後面多 / 導致跨域的問題 fix: 修復夜間模式下,小屏幕的toc 滾動條顏色不明顯的 bug fix: 修復設置字體超過17px時,toc 裏面的邊框異常的 bug improvement: 優化語言文件部分用詞 improvement: disqus 和 disqusjs 的評論數獲取不到時,顯示為 0 improvement: disqusjs 的評論數改為 api 獲取 improvement: 代碼優化 improvement: 更新 plugins.yml
This commit is contained in:
@@ -1,36 +1,36 @@
|
||||
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
|
||||
hexo.extend.helper.register('getArchiveLength', function () {
|
||||
const { archive_generator: archiveGenerator } = hexo.config
|
||||
if (archiveGenerator && archiveGenerator.enable === false) return this.site.posts.length
|
||||
const { yearly, monthly, daily } = archiveGenerator
|
||||
const { year, month, day } = this.page
|
||||
if (yearly === false || !year) return allPostsLength
|
||||
if (yearly === false || !year) return this.site.posts.length
|
||||
|
||||
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
|
||||
switch (type) {
|
||||
case 'year':
|
||||
return y1 === y2
|
||||
case 'month':
|
||||
return y1 === y2 && m1 === m2
|
||||
case 'day':
|
||||
return y1 === y2 && m1 === m2 && d1 === d2
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const generateDateObj = (type) => {
|
||||
const dateObj = []
|
||||
let length = 0
|
||||
|
||||
posts.forEach(post => {
|
||||
return posts.reduce((dateObj, post) => {
|
||||
const date = post.date.clone()
|
||||
const year = date.year()
|
||||
const month = date.month() + 1
|
||||
const day = date.date()
|
||||
const lastData = dateObj[length - 1]
|
||||
const lastData = dateObj[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({
|
||||
dateObj.push({
|
||||
name,
|
||||
year,
|
||||
month,
|
||||
@@ -40,19 +40,19 @@ hexo.extend.helper.register('findArchiveLength', function (func) {
|
||||
} else {
|
||||
lastData.count++
|
||||
}
|
||||
})
|
||||
|
||||
return dateObj
|
||||
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 data = this.fragment_cache('createArchiveObj', () => {
|
||||
const dateObjs = []
|
||||
if (yearly) dateObjs.push(...generateDateObj('year'))
|
||||
if (monthly) dateObjs.push(...generateDateObj('month'))
|
||||
if (daily) dateObjs.push(...generateDateObj('day'))
|
||||
return dateObjs
|
||||
})
|
||||
|
||||
const name = month ? day ? `${year}-${month}-${day}` : `${year}-${month}` : year
|
||||
const name = month ? (day ? `${year}-${month}-${day}` : `${year}-${month}`) : year
|
||||
return data.find(item => item.name === name).count
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user