mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-08 12:07:06 +08:00
update
This commit is contained in:
@@ -7,11 +7,18 @@ hexo.extend.filter.register('before_generate', () => {
|
||||
let { use } = themeConfig.comments
|
||||
if (!use) return
|
||||
|
||||
// 確保 use 是一個陣列
|
||||
// Make sure use is an array
|
||||
use = Array.isArray(use) ? use : use.split(',')
|
||||
|
||||
// 將每個項目轉換為小寫並將首字母大寫
|
||||
themeConfig.comments.use = use.map(item =>
|
||||
// Capitalize the first letter of each comment name
|
||||
use = use.map(item =>
|
||||
item.trim().toLowerCase().replace(/\b[a-z]/g, s => s.toUpperCase())
|
||||
)
|
||||
|
||||
// Disqus and Disqusjs conflict, only keep the first one
|
||||
if (use.includes('Disqus') && use.includes('Disqusjs')) {
|
||||
use = [use[0]]
|
||||
}
|
||||
|
||||
themeConfig.comments.use = use
|
||||
})
|
||||
|
||||
@@ -55,7 +55,6 @@ hexo.extend.helper.register('inject_head_js', function () {
|
||||
if (!${pjax.enable} && key.startsWith('pjax')) return
|
||||
const globalFn = parent.globalFn || {}
|
||||
globalFn[key] = globalFn[key] || {}
|
||||
if (name && globalFn[key][name]) return
|
||||
globalFn[key][name || Object.keys(globalFn[key]).length] = fn
|
||||
parent.globalFn = globalFn
|
||||
}
|
||||
|
||||
@@ -5,13 +5,6 @@ const { prettyUrls } = require('hexo-util')
|
||||
const crypto = require('crypto')
|
||||
const moment = require('moment-timezone')
|
||||
|
||||
hexo.extend.helper.register('getTimeZoneDate', date => {
|
||||
// This is a hack method, because hexo treats time as UTC time
|
||||
// so you need to manually convert the time zone
|
||||
const utcDate = moment.utc(date).format('YYYY-MM-DD HH:mm:ss')
|
||||
return moment.tz(utcDate, hexo.config.timezone).format('YYYY-MM-DD HH:mm:ss')
|
||||
})
|
||||
|
||||
hexo.extend.helper.register('truncate', truncateContent)
|
||||
|
||||
hexo.extend.helper.register('postDesc', data => {
|
||||
@@ -103,3 +96,31 @@ hexo.extend.helper.register('getBgPath', path => {
|
||||
return `background: ${path};`
|
||||
}
|
||||
})
|
||||
|
||||
hexo.extend.helper.register('shuoshuoFN', (data, page) => {
|
||||
const { limit } = page
|
||||
let finalResult = ''
|
||||
|
||||
// Check if limit.value is a valid date
|
||||
const isValidDate = (date) => !isNaN(Date.parse(date))
|
||||
|
||||
// order by date
|
||||
data.sort((a, b) => Date.parse(b.date) - Date.parse(a.date))
|
||||
|
||||
// Apply number limit or time limit conditionally
|
||||
if (limit && limit.type === 'num' && limit.value > 0) {
|
||||
finalResult = data.slice(0, limit.value)
|
||||
} else if (limit && limit.type === 'date' && isValidDate(limit.value)) {
|
||||
const limitDate = Date.parse(limit.value)
|
||||
finalResult = data.filter(item => Date.parse(item.date) >= limitDate)
|
||||
}
|
||||
|
||||
// This is a hack method, because hexo treats time as UTC time
|
||||
// so you need to manually convert the time zone
|
||||
finalResult.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')
|
||||
})
|
||||
|
||||
return finalResult
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user