fix(blog): restore prev/next post navigation buttons (#346)

Co-authored-by: 0bipinnata0 <0bipinnata0@users.noreply.github.com>
This commit is contained in:
0bipinnata0
2025-03-28 21:28:17 +08:00
committed by GitHub
parent d15139ad11
commit b826152352
2 changed files with 5 additions and 9 deletions

View File

@@ -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 },

View File

@@ -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