112 lines
2.2 KiB
Plaintext
112 lines
2.2 KiB
Plaintext
---
|
|
import Layout from "@/layouts/Layout.astro";
|
|
|
|
import {http} from "@/lib/request";
|
|
import {formatDatetime} from "@/lib/format.ts";
|
|
|
|
interface Post {
|
|
title: string;
|
|
summary: string;
|
|
slug: string;
|
|
cover: string;
|
|
category_name: string;
|
|
published_at: string;
|
|
}
|
|
|
|
const {list} = await http.get<ApiPageResponse<Post>>("post");
|
|
|
|
list.map((post) => {
|
|
post.published_at = formatDatetime(post.published_at, 'YYYY 年 M 月 D 日')
|
|
})
|
|
---
|
|
|
|
<Layout>
|
|
<div class="posts">
|
|
{
|
|
list.map((post) => (
|
|
<a class="post" href={`/posts/${post.slug}`}>
|
|
<div class="published-at">{post.published_at}</div>
|
|
<div class="category-name">{post.category_name}</div>
|
|
<div class="post-title">{post.title}</div>
|
|
<div class="link">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
|
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
|
class="lucide lucide-arrow-up-right-icon lucide-arrow-up-right">
|
|
<path d="M7 7h10v10"/>
|
|
<path d="M7 17 17 7"/>
|
|
</svg>
|
|
</div>
|
|
</a>
|
|
))
|
|
}
|
|
</div>
|
|
</Layout>
|
|
|
|
<style>
|
|
.posts {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 20px;
|
|
}
|
|
|
|
.post {
|
|
background: #fff;
|
|
padding: 16px;
|
|
border-radius: 12px;
|
|
box-shadow: rgba(0, 0, 0, 0.05) 0px 1px 2px 0px;
|
|
display: flex;
|
|
align-items: center;
|
|
transition: transform 0.2s linear;
|
|
}
|
|
|
|
.post:hover {
|
|
box-shadow: rgba(33, 35, 38, 0.1) 0px 10px 10px -10px;
|
|
}
|
|
|
|
.published-at {
|
|
white-space: nowrap;
|
|
font-size: 14px;
|
|
color: #4b5563;
|
|
min-width: 130px;
|
|
margin-right: 20px;
|
|
}
|
|
|
|
.category-name {
|
|
border-radius: 999px;
|
|
background: #fceeda;
|
|
padding: 4px 12px;
|
|
font-size: 14px;
|
|
margin-right: 24px;
|
|
}
|
|
|
|
.post-title {
|
|
flex: 1;
|
|
white-space: nowrap;
|
|
text-overflow: ellipsis;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.link {
|
|
}
|
|
|
|
.link svg {
|
|
width: 16px;
|
|
height: 16px;
|
|
color: #6b7280;
|
|
}
|
|
|
|
@media (max-width: 640px) {
|
|
.posts {
|
|
gap: 12px;
|
|
}
|
|
|
|
.published-at {
|
|
margin-right: 8px;
|
|
}
|
|
|
|
.category-name {
|
|
display: none;
|
|
}
|
|
}
|
|
</style>
|