feat: 根据分类和tag筛选文章

This commit is contained in:
2026-08-05 20:38:48 +08:00
parent f7b7f7d320
commit ecf730bda7
6 changed files with 568 additions and 17 deletions

View File

@@ -1,12 +1,15 @@
---
import Folder from "@/assets/icon/folder.png?url";
import Tag from "@/assets/icon/tag.png?url";
import type { CategoriesStats } from "@/types";
import TagIcon from "@/assets/icon/tag.png?url";
import type { CategoriesStats,Tag } from "@/types";
import { createHttp } from "@/lib/request";
const http = createHttp(Astro.request.headers);
const { data: categories } =
await http.get<ApiResponse<CategoriesStats[]>>("categories/stats");
const { data: tags } =
await http.get<ApiResponse<Tag[]>>("posts/tags");
---
<aside class="sidebar">
@@ -19,7 +22,12 @@ const { data: categories } =
{
categories.map((category) => (
<li>
<a>{category.name}</a>
<a
href={`/filter?type=category&code=${encodeURIComponent(category.code)}`}
title={`${category.name} · ${category.post_count} 篇`}
>
{category.name}
</a>
<span class="count">{category.post_count}</span>
</li>
))
@@ -29,20 +37,20 @@ const { data: categories } =
<div class="widget">
<h3 class="widget-title">
<img src={Tag} alt="Folder" />
<img src={TagIcon} alt="Tag" />
标签云
</h3>
<div class="tag-cloud">
<a class="tag" href="#">HTML</a>
<a class="tag" href="#">CSS</a>
<a class="tag" href="#">JavaScript</a>
<a class="tag" href="#">响应式</a>
<a class="tag" href="#">随笔</a>
<a class="tag" href="#">读书</a>
<a class="tag" href="#">效率</a>
<a class="tag" href="#">设计</a>
<a class="tag" href="#">工具</a>
<a class="tag" href="#">深色模式</a>
{
tags.map((tag) => (
<a
class="tag"
href={`/filter?type=tag&code=${encodeURIComponent(tag.code)}`}
>
{tag.name}
</a>
))
}
</div>
</div>
</aside>
@@ -126,7 +134,7 @@ const { data: categories } =
}
.tag:hover {
background: #dfe6fd;
background: var(--tag-hover-bg);
}
@media (max-width: 860px) {