archieve 排序

This commit is contained in:
tangly1024.com
2023-06-30 11:51:08 +08:00
parent 8103e23aac
commit 43b6be392d
2 changed files with 4 additions and 7 deletions

View File

@@ -9,9 +9,7 @@ export default function formatDate (date, local) {
const d = new Date(date)
const options = { year: 'numeric', month: 'short', day: 'numeric' }
const res = d.toLocaleDateString(local, options)
return local.slice(0, 2).toLowerCase() === 'zh'
? res.replace('年', '-').replace('月', '-').replace('日', '')
: res
return res
}
export function formatDateFmt (timestamp, fmt) {

View File

@@ -4,6 +4,7 @@ import { useGlobal } from '@/lib/global'
import BLOG from '@/blog.config'
import { useRouter } from 'next/router'
import { getLayoutByTheme } from '@/themes/theme'
import { formatDateFmt } from '@/lib/formatDate'
const ArchiveIndex = props => {
const { siteInfo } = props
@@ -34,15 +35,13 @@ export async function getStaticProps() {
const postsSortByDate = Object.create(props.posts)
postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.publishTime || a.createdTime)
const dateB = new Date(b?.publishTime || b.createdTime)
return dateB - dateA
return b?.sortDate - a?.sortDate
})
const archivePosts = {}
postsSortByDate.forEach(post => {
const date = post.date?.start_date?.slice(0, 7) || post.createdTime
const date = formatDateFmt(post.sortDate, 'yyyy-MM')
if (archivePosts[date]) {
archivePosts[date].push(post)
} else {