152 lines
2.8 KiB
Plaintext
152 lines
2.8 KiB
Plaintext
---
|
|
import Folder from "@/assets/icon/folder.png?url";
|
|
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">
|
|
<div class="widget">
|
|
<h3 class="widget-title">
|
|
<img src={Folder} alt="Folder" />
|
|
文章分类
|
|
</h3>
|
|
<ul class="category-list">
|
|
{
|
|
categories.map((category) => (
|
|
<li>
|
|
<a
|
|
href={`/search?c=${encodeURIComponent(category.code)}`}
|
|
title={`${category.name} · ${category.post_count} 篇`}
|
|
>
|
|
{category.name}
|
|
</a>
|
|
<span class="count">{category.post_count}</span>
|
|
</li>
|
|
))
|
|
}
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="widget">
|
|
<h3 class="widget-title">
|
|
<img src={TagIcon} alt="Tag" />
|
|
标签云
|
|
</h3>
|
|
<div class="tag-cloud">
|
|
{
|
|
tags.map((tag) => (
|
|
<a
|
|
class="tag"
|
|
href={`/search?t=${encodeURIComponent(tag.code)}`}
|
|
>
|
|
{tag.name}
|
|
</a>
|
|
))
|
|
}
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
|
|
<style>
|
|
.sidebar {
|
|
width: 300px;
|
|
height: 100%;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 20px;
|
|
}
|
|
|
|
.widget {
|
|
background: var(--card-bg);
|
|
border-radius: 12px;
|
|
box-shadow: var(--shadow);
|
|
padding: 22px;
|
|
}
|
|
|
|
.widget-title {
|
|
font-size: 16px;
|
|
font-weight: 700;
|
|
margin-bottom: 16px;
|
|
padding-bottom: 10px;
|
|
border-bottom: 1px solid var(--border);
|
|
display: flex;
|
|
gap: 8px;
|
|
}
|
|
|
|
.widget-title img {
|
|
width: 18px;
|
|
height: 18px;
|
|
}
|
|
|
|
/* 分类 & 标签云 */
|
|
.category-list {
|
|
list-style: none;
|
|
}
|
|
|
|
.category-list li {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
padding: 8px 4px;
|
|
font-size: 14px;
|
|
border-bottom: 1px dashed var(--border);
|
|
}
|
|
|
|
.category-list li:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.category-list a:hover {
|
|
color: #4f6df5;
|
|
}
|
|
|
|
.category-list .count {
|
|
color: var(--text-secondary);
|
|
font-size: 13px;
|
|
}
|
|
|
|
.tag-cloud {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 8px;
|
|
}
|
|
|
|
.tags {
|
|
display: flex;
|
|
gap: 8px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.tag {
|
|
font-size: 12px;
|
|
color: var(--tag-text);
|
|
background: var(--tag-bg);
|
|
padding: 3px 10px;
|
|
border-radius: 999px;
|
|
transition: background 0.2s;
|
|
}
|
|
|
|
.tag:hover {
|
|
background: var(--tag-hover-bg);
|
|
}
|
|
|
|
@media (max-width: 860px) {
|
|
.sidebar {
|
|
width: 100%;
|
|
}
|
|
}
|
|
|
|
@media (max-width: 860px) {
|
|
.sidebar {
|
|
gap: 16px;
|
|
}
|
|
}
|
|
</style>
|