From b826152352898be68509b0a9a76148361578ed48 Mon Sep 17 00:00:00 2001 From: 0bipinnata0 <47297706+0bipinnata0@users.noreply.github.com> Date: Fri, 28 Mar 2025 21:28:17 +0800 Subject: [PATCH] fix(blog): restore prev/next post navigation buttons (#346) Co-authored-by: 0bipinnata0 <0bipinnata0@users.noreply.github.com> --- src/pages/posts/[...slug].astro | 5 ++--- src/utils/content-utils.ts | 9 +++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 99fd119b..0585ddc4 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -13,11 +13,10 @@ import PostMetadata from '../../components/PostMeta.astro' import ImageWrapper from '../../components/misc/ImageWrapper.astro' import { profileConfig, siteConfig } from '../../config' import { formatDateToYYYYMMDD } from '../../utils/date-utils' +import { getSortedPosts } from '@utils/content-utils' export async function getStaticPaths() { - const blogEntries = await getCollection('posts', ({ data }) => { - return import.meta.env.PROD ? data.draft !== true : true - }) + const blogEntries = await getSortedPosts(); return blogEntries.map(entry => ({ params: { slug: entry.slug }, props: { entry }, diff --git a/src/utils/content-utils.ts b/src/utils/content-utils.ts index d1ee224a..74e551a6 100644 --- a/src/utils/content-utils.ts +++ b/src/utils/content-utils.ts @@ -1,17 +1,14 @@ import { getCollection } from 'astro:content' -import type { BlogPostData } from '@/types/config' import I18nKey from '@i18n/i18nKey' import { i18n } from '@i18n/translation' -export async function getSortedPosts(): Promise< - { body: string, data: BlogPostData; slug: string }[] -> { +export async function getSortedPosts() { const allBlogPosts = (await getCollection('posts', ({ data }) => { return import.meta.env.PROD ? data.draft !== true : true - })) as unknown as { body: string, data: BlogPostData; slug: string }[] + })) const sorted = allBlogPosts.sort( - (a: { data: BlogPostData }, b: { data: BlogPostData }) => { + (a, b) => { const dateA = new Date(a.data.published) const dateB = new Date(b.data.published) return dateA > dateB ? -1 : 1