feat(blog): 重构文章和笔记展示,优化分类和标签

This commit is contained in:
KazooTTT
2025-03-05 16:14:05 +08:00
parent 013ede32a4
commit e6a88b73af
20 changed files with 263 additions and 196 deletions

View File

@ -1,28 +1,23 @@
---
import { type CollectionEntry, getCollection } from "astro:content";
import SocialList from "@/components/SocialList.astro";
import PostPreview from "@/components/blog/PostPreview.astro";
import Note from "@/components/note/Note.astro";
import { getAllFixedToTopPosts, getAllPosts } from "@/data/post";
import { getAllFixedToTopPosts, getAllNotes, getAllPosts } from "@/data/post";
import PageLayout from "@/layouts/Base.astro";
import { collectionDateSort } from "@/utils/date";
// Posts
const MAX_POSTS = 10;
const allPosts = await getAllPosts();
const allPostsByDate = allPosts
.sort(collectionDateSort)
.slice(0, MAX_POSTS) as CollectionEntry<"post">[];
const allPostsByDate = allPosts.sort(collectionDateSort).slice(0, MAX_POSTS);
// Fixed to top Posts
const allFixedToTopPosts = await getAllFixedToTopPosts();
const allFixedToTopPostsByDate = allFixedToTopPosts
.sort(collectionDateSort)
.slice(0, MAX_POSTS) as CollectionEntry<"post">[];
const allFixedToTopPostsByDate = allFixedToTopPosts.sort(collectionDateSort).slice(0, MAX_POSTS);
// Notes
const MAX_NOTES = 6;
const allNotes = await getCollection("note");
const allNotes = await getAllNotes();
const latestNotes = allNotes.sort(collectionDateSort).slice(0, MAX_NOTES);
---
@ -36,15 +31,15 @@ const latestNotes = allNotes.sort(collectionDateSort).slice(0, MAX_NOTES);
{
allFixedToTopPostsByDate.length > 0 && (
<section class="mt-16">
<h2 class="title text-accent mb-6 text-xl"><a href="/posts/">置顶文章</a></h2>
<h2 class="title text-accent mb-6 text-xl">
<a href="/posts/">置顶文章</a>
</h2>
<ul class="space-y-4" role="list">
{
allFixedToTopPostsByDate.map((p) => (
<li class="grid gap-2 sm:grid-cols-[auto_1fr]">
<PostPreview post={p} />
</li>
))
}
{allFixedToTopPostsByDate.map((p) => (
<li class="grid gap-2 sm:grid-cols-[auto_1fr]">
<PostPreview post={p} />
</li>
))}
</ul>
</section>
)