fix: sort posts in [tag] page (#101)

* fix: sorted posts in tags page
This commit is contained in:
Parinya T
2023-08-09 14:38:16 +07:00
committed by GitHub
parent b118f09d5d
commit b571816dcd
+4 -1
View File
@@ -9,6 +9,7 @@ import getUniqueTags from "@utils/getUniqueTags";
import getPostsByTag from "@utils/getPostsByTag";
import slugify from "@utils/slugify";
import { SITE } from "@config";
import getSortedPosts from "@utils/getSortedPosts";
export interface Props {
post: CollectionEntry<"blog">;
@@ -33,6 +34,8 @@ const { tag } = Astro.props;
const posts = await getCollection("blog", ({ data }) => !data.draft);
const tagPosts = getPostsByTag(posts, tag);
const sortTagsPost = getSortedPosts(tagPosts);
---
<Layout title={`Tag:${tag} | ${SITE.title}`}>
@@ -43,7 +46,7 @@ const tagPosts = getPostsByTag(posts, tag);
>
<ul>
{
tagPosts.map(({ data }) => (
sortTagsPost.map(({ data }) => (
<Card href={`/posts/${slugify(data)}`} frontmatter={data} />
))
}