mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-11 23:02:53 +01:00
fix(blog): restore prev/next post navigation buttons (#346)
Co-authored-by: 0bipinnata0 <0bipinnata0@users.noreply.github.com>
This commit is contained in:
@@ -13,11 +13,10 @@ import PostMetadata from '../../components/PostMeta.astro'
|
|||||||
import ImageWrapper from '../../components/misc/ImageWrapper.astro'
|
import ImageWrapper from '../../components/misc/ImageWrapper.astro'
|
||||||
import { profileConfig, siteConfig } from '../../config'
|
import { profileConfig, siteConfig } from '../../config'
|
||||||
import { formatDateToYYYYMMDD } from '../../utils/date-utils'
|
import { formatDateToYYYYMMDD } from '../../utils/date-utils'
|
||||||
|
import { getSortedPosts } from '@utils/content-utils'
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const blogEntries = await getCollection('posts', ({ data }) => {
|
const blogEntries = await getSortedPosts();
|
||||||
return import.meta.env.PROD ? data.draft !== true : true
|
|
||||||
})
|
|
||||||
return blogEntries.map(entry => ({
|
return blogEntries.map(entry => ({
|
||||||
params: { slug: entry.slug },
|
params: { slug: entry.slug },
|
||||||
props: { entry },
|
props: { entry },
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
import { getCollection } from 'astro:content'
|
import { getCollection } from 'astro:content'
|
||||||
import type { BlogPostData } from '@/types/config'
|
|
||||||
import I18nKey from '@i18n/i18nKey'
|
import I18nKey from '@i18n/i18nKey'
|
||||||
import { i18n } from '@i18n/translation'
|
import { i18n } from '@i18n/translation'
|
||||||
|
|
||||||
export async function getSortedPosts(): Promise<
|
export async function getSortedPosts() {
|
||||||
{ body: string, data: BlogPostData; slug: string }[]
|
|
||||||
> {
|
|
||||||
const allBlogPosts = (await getCollection('posts', ({ data }) => {
|
const allBlogPosts = (await getCollection('posts', ({ data }) => {
|
||||||
return import.meta.env.PROD ? data.draft !== true : true
|
return import.meta.env.PROD ? data.draft !== true : true
|
||||||
})) as unknown as { body: string, data: BlogPostData; slug: string }[]
|
}))
|
||||||
|
|
||||||
const sorted = allBlogPosts.sort(
|
const sorted = allBlogPosts.sort(
|
||||||
(a: { data: BlogPostData }, b: { data: BlogPostData }) => {
|
(a, b) => {
|
||||||
const dateA = new Date(a.data.published)
|
const dateA = new Date(a.data.published)
|
||||||
const dateB = new Date(b.data.published)
|
const dateB = new Date(b.data.published)
|
||||||
return dateA > dateB ? -1 : 1
|
return dateA > dateB ? -1 : 1
|
||||||
|
|||||||
Reference in New Issue
Block a user