This commit is contained in:
myw
2024-11-02 19:38:15 +08:00
parent 7b6a386a14
commit fb4ab20169

View File

@@ -102,19 +102,26 @@ hexo.extend.helper.register('shuoshuoFN', (data, page) => {
let finalResult = '' let finalResult = ''
// Check if limit.value is a valid date // Check if limit.value is a valid date
const isValidDate = (date) => !isNaN(Date.parse(date)) const isValidDate = date => !isNaN(Date.parse(date))
// order by date // order by date
data.sort((a, b) => Date.parse(b.date) - Date.parse(a.date)) const orderByDate = data => data.sort((a, b) => Date.parse(b.date) - Date.parse(a.date))
// Apply number limit or time limit conditionally // Apply number limit or time limit conditionally
const limitData = data => {
if (limit && limit.type === 'num' && limit.value > 0) { if (limit && limit.type === 'num' && limit.value > 0) {
finalResult = data.slice(0, limit.value) return data.slice(0, limit.value)
} else if (limit && limit.type === 'date' && isValidDate(limit.value)) { } else if (limit && limit.type === 'date' && isValidDate(limit.value)) {
const limitDate = Date.parse(limit.value) const limitDate = Date.parse(limit.value)
finalResult = data.filter(item => Date.parse(item.date) >= limitDate) return data.filter(item => Date.parse(item.date) >= limitDate)
} }
return data
}
orderByDate(data)
finalResult = limitData(data)
// This is a hack method, because hexo treats time as UTC time // This is a hack method, because hexo treats time as UTC time
// so you need to manually convert the time zone // so you need to manually convert the time zone
finalResult.forEach(item => { finalResult.forEach(item => {