mirror of
https://github.com/KazooTTT/kazoottt-blog-v2.git
synced 2025-06-23 10:41:30 +08:00
feat: 新增分类
This commit is contained in:
35
src/pages/categories/index.astro
Normal file
35
src/pages/categories/index.astro
Normal file
@ -0,0 +1,35 @@
|
||||
---
|
||||
import { getAllPosts, getUniqueCategoriesWithCount } from "@/data/post";
|
||||
import PageLayout from "@/layouts/Base.astro";
|
||||
|
||||
const allPosts = await getAllPosts();
|
||||
const allCategories = getUniqueCategoriesWithCount(allPosts);
|
||||
|
||||
const meta = {
|
||||
description: "A list of all the categories I've written about in my posts",
|
||||
title: "All Categories",
|
||||
};
|
||||
---
|
||||
|
||||
<PageLayout meta={meta}>
|
||||
<h1 class="title mb-6">Categories</h1>
|
||||
<ul class="space-y-4">
|
||||
{
|
||||
allCategories.map(([item, val]) => (
|
||||
<li class="flex items-center gap-x-2">
|
||||
<a
|
||||
class="cactus-link inline-block"
|
||||
data-astro-prefetch
|
||||
href={`/categories/${item}/`}
|
||||
title={`View posts with the category: ${item}`}
|
||||
>
|
||||
#{item}
|
||||
</a>
|
||||
<span class="inline-block">
|
||||
- {val} Post{val > 1 && "s"}
|
||||
</span>
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
</PageLayout>
|
Reference in New Issue
Block a user