diff --git a/lib/formatDate.js b/lib/formatDate.js index 6f274da8..dae1b68a 100644 --- a/lib/formatDate.js +++ b/lib/formatDate.js @@ -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) { diff --git a/pages/archive/index.js b/pages/archive/index.js index 6d0ebe32..ffba2787 100644 --- a/pages/archive/index.js +++ b/pages/archive/index.js @@ -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 {