This commit is contained in:
myw
2026-07-16 16:53:38 +08:00 Unverified
parent 6b44647d4e
commit d8942c236a
22 changed files with 263 additions and 240 deletions
+6 -7
View File
@@ -17,12 +17,11 @@ hexo.extend.helper.register('getArchiveLength', function () {
const m = date.month() + 1
const d = date.date()
if (yearly) {
const keyYear = `${y}`
map.set(keyYear, (map.get(keyYear) || 0) + 1)
}
// Always track year so year archive pages can be counted
const keyYear = `${y}`
map.set(keyYear, (map.get(keyYear) || 0) + 1)
if (monthly) {
if (monthly || daily) {
const keyMonth = `${y}-${m}`
map.set(keyMonth, (map.get(keyMonth) || 0) + 1)
}
@@ -37,8 +36,8 @@ hexo.extend.helper.register('getArchiveLength', function () {
// 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 (yearly || monthly || daily) key = `${year}`
if ((monthly || daily) && month) key = `${year}-${month}`
if (daily && day) key = `${year}-${month}-${day}`
// Return the count for the current period or default to the total posts
+11 -12
View File
@@ -11,6 +11,8 @@ const colorPattern = /^(#|rgb|rgba|hsl|hsla)/i
const simpleFilePattern = /\.(png|jpg|jpeg|gif|bmp|webp|svg|tiff)$/i
const archiveRegex = /\/archives\//
const { version: themeVersion } = require('../../package.json')
hexo.extend.helper.register('truncate', truncateContent)
hexo.extend.helper.register('postDesc', data => {
@@ -58,8 +60,6 @@ hexo.extend.helper.register('cloudTags', function (options = {}) {
const userColors = normalizeColors(custom_colors)
const resolveColorClass = (idx) => `tag-color-${idx % userColors.length}`
const generateStyle = (size, unit, page, color) => {
const colorStyle = page === 'tags' ? `background-color: ${color};` : `color: ${color};`
return `font-size: ${parseFloat(size.toFixed(2))}${unit}; ${colorStyle}`
@@ -70,10 +70,9 @@ hexo.extend.helper.register('cloudTags', function (options = {}) {
const size = minfontsize + ((maxfontsize - minfontsize) * ratio)
if (userColors && userColors.length) {
const colorClass = resolveColorClass(idx)
const color = userColors[idx % userColors.length]
const style = generateStyle(size, unit, page, color)
return `<a href="${env.url_for(tag.path)}" class="tag-cloud-item ${colorClass}" style="${style}">${tag.name}</a>`
return `<a href="${env.url_for(tag.path)}" class="tag-cloud-item" style="${style}">${tag.name}</a>`
}
const color = getRandomColor()
@@ -105,13 +104,13 @@ hexo.extend.helper.register('findArchivesTitle', function (page, menu, date) {
if (!menu) return defaultTitle
const loop = m => {
for (const key in m) {
if (typeof m[key] === 'object') {
const result = loop(m[key])
for (const [key, value] of Object.entries(m)) {
if (value && typeof value === 'object') {
const result = loop(value)
if (result) return result
}
if (archiveRegex.test(m[key])) {
if (typeof value === 'string' && archiveRegex.test(value)) {
return key
}
}
@@ -154,9 +153,10 @@ hexo.extend.helper.register('shuoshuoFN', (data, page) => {
// This is a hack method, because hexo treats time as UTC time
// so you need to manually convert the time zone
const timezone = hexo.config.timezone
processedData.forEach(item => {
const utcDate = moment.utc(item.date).format('YYYY-MM-DD HH:mm:ss')
item.date = moment.tz(utcDate, hexo.config.timezone).format('YYYY-MM-DD HH:mm:ss')
const parsed = moment.utc(item.date)
item.date = moment.tz(parsed.format('YYYY-MM-DD HH:mm:ss'), timezone).format('YYYY-MM-DD HH:mm:ss')
// markdown
item.content = hexo.render.renderSync({ text: item.content, engine: 'markdown' })
})
@@ -179,8 +179,7 @@ hexo.extend.helper.register('getPageType', (page, isHome) => {
})
hexo.extend.helper.register('getVersion', () => {
const { version } = require('../../package.json')
return { hexo: hexo.version, theme: version }
return { hexo: hexo.version, theme: themeVersion }
})
hexo.extend.helper.register('safeJSON', data => {
+9 -7
View File
@@ -23,7 +23,6 @@ hexo.extend.helper.register('related_posts', function (currentPost) {
if (relatedPosts.has(post.path)) {
relatedPosts.get(post.path).weight += 1
} else {
const getPostDesc = post.postDesc || postDesc(post, hexo)
relatedPosts.set(post.path, {
title: post.title,
path: post.path,
@@ -32,7 +31,7 @@ hexo.extend.helper.register('related_posts', function (currentPost) {
weight: 1,
updated: post.updated,
created: post.date,
postDesc: getPostDesc,
post,
random: Math.random()
})
}
@@ -61,12 +60,15 @@ hexo.extend.helper.register('related_posts', function (currentPost) {
result += `<div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>${headlineLang}</span></div>`
result += '<div class="relatedPosts-list">'
for (let i = 0; i < Math.min(relatedPostsList.length, limitNum); i++) {
let { cover, title, path, cover_type, created, updated, postDesc } = relatedPostsList[i]
const max = Math.min(relatedPostsList.length, limitNum)
for (let i = 0; i < max; i++) {
const item = relatedPostsList[i]
let { cover, title, path, cover_type, created, updated, post } = item
const { escape_html, url_for, date } = this
cover = cover || 'var(--default-bg-color)'
title = escape_html(title)
const className = postDesc ? 'pagination-related' : 'pagination-related no-desc'
const desc = post.postDesc || postDesc(post, hexo)
const className = desc ? 'pagination-related' : 'pagination-related no-desc'
result += `<a class="${className}" href="${url_for(path)}" title="${title}">`
if (cover_type === 'img') {
result += `<img class="cover" src="${url_for(cover)}" alt="cover">`
@@ -80,8 +82,8 @@ hexo.extend.helper.register('related_posts', function (currentPost) {
}
result += `<div class="info-item-2">${title}</div></div>`
if (postDesc) {
result += `<div class="info-2"><div class="info-item-1">${postDesc}</div></div>`
if (desc) {
result += `<div class="info-2"><div class="info-item-1">${desc}</div></div>`
}
result += '</div></a>'
}