Merge pull request #708 from L4ys/main

fix: sort posts in tags page
This commit is contained in:
Timothy 2023-09-08 15:49:32 +08:00 committed by GitHub
commit 2cd0c8184a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import { slug } from 'github-slugger'
import { allCoreContent } from 'pliny/utils/contentlayer'
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer'
import siteMetadata from '@/data/siteMetadata'
import ListLayout from '@/layouts/ListLayoutWithTags'
import { allBlogs } from 'contentlayer/generated'
@ -35,7 +35,7 @@ export default function TagPage({ params }: { params: { tag: string } }) {
// Capitalize first letter and convert space to dash
const title = tag[0].toUpperCase() + tag.split(' ').join('-').slice(1)
const filteredPosts = allCoreContent(
allBlogs.filter((post) => post.tags && post.tags.map((t) => slug(t)).includes(tag))
sortPosts(allBlogs.filter((post) => post.tags && post.tags.map((t) => slug(t)).includes(tag)))
)
return <ListLayout posts={filteredPosts} title={title} />
}