mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-08 12:07:06 +08:00
- Bump version from 5.5.3-b2 to 5.5.3 in package.json - Update third-party dependencies: * algolia_search: 5.43.0 -> 5.46.0 * docsearch: 4.3.1 -> 4.3.2 * fancybox: 6.1.4 -> 6.1.7 * katex: 0.16.25 -> 0.16.27 * mermaid: 11.12.1 -> 11.12.2 * waline: 3.7.1 -> 3.8.0 perf: optimize JavaScript performance - Add defer attribute to script tags in pjax and prismjs - Improve DOM content loading timing in pjax - Optimize utilities with better throttle implementation - Cache header positions for TOC performance - Optimize related posts generation with Maps - Improve archive helpers performance fix: improve error handling and UI fixes - Replace process.exit with proper error throwing - Fix tooltip positioning with boundary checks - Add btn-effects to readmode exit button - Fix element height calculation for hidden elements - Improve image filters in dark mode (brightness .88, contrast .95) style: code improvements and consistency - Refactor random cover generation with generator pattern - Optimize data processing in helpers - Clean up unused functions and improve code structure - Fix Chinese translation: 页 -> 頁
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
hexo.extend.helper.register('getArchiveLength', function () {
|
|
const archiveGenerator = hexo.config.archive_generator
|
|
const posts = this.site.posts
|
|
|
|
const { yearly, monthly, daily } = archiveGenerator
|
|
const { year, month, day } = this.page
|
|
|
|
// Archives Page
|
|
if (!year) return posts.length
|
|
|
|
// Create a map to count posts per period
|
|
const mapData = this.fragment_cache('createArchiveObj', () => {
|
|
const map = new Map()
|
|
posts.forEach(post => {
|
|
const date = post.date
|
|
const y = date.year()
|
|
const m = date.month() + 1
|
|
const d = date.date()
|
|
|
|
if (yearly) {
|
|
const keyYear = `${y}`
|
|
map.set(keyYear, (map.get(keyYear) || 0) + 1)
|
|
}
|
|
|
|
if (monthly) {
|
|
const keyMonth = `${y}-${m}`
|
|
map.set(keyMonth, (map.get(keyMonth) || 0) + 1)
|
|
}
|
|
|
|
if (daily) {
|
|
const keyDay = `${y}-${m}-${d}`
|
|
map.set(keyDay, (map.get(keyDay) || 0) + 1)
|
|
}
|
|
})
|
|
return map
|
|
})
|
|
|
|
// Determine the appropriate key to fetch based on current page context
|
|
let key
|
|
if (yearly && year) key = `${year}`
|
|
if (monthly && month) key = `${year}-${month}`
|
|
if (daily && day) key = `${year}-${month}-${day}`
|
|
|
|
// Return the count for the current period or default to the total posts
|
|
return mapData.get(key) || posts.length
|
|
})
|