From fb4ab2016929dc04e9f643760b6a019f754be5e0 Mon Sep 17 00:00:00 2001 From: myw Date: Sat, 2 Nov 2024 19:38:15 +0800 Subject: [PATCH] update --- scripts/helpers/page.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/scripts/helpers/page.js b/scripts/helpers/page.js index c3d764354..cb9784283 100644 --- a/scripts/helpers/page.js +++ b/scripts/helpers/page.js @@ -102,19 +102,26 @@ hexo.extend.helper.register('shuoshuoFN', (data, page) => { let finalResult = '' // 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 - 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 - 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) + const limitData = data => { + if (limit && limit.type === 'num' && limit.value > 0) { + return data.slice(0, limit.value) + } else if (limit && limit.type === 'date' && isValidDate(limit.value)) { + const limitDate = Date.parse(limit.value) + 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 // so you need to manually convert the time zone finalResult.forEach(item => {