feat: 归档页面
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
---
|
||||
import Layout from "@/layouts/Layout.astro";
|
||||
import type {Archive} from "@/types/archive";
|
||||
import {createHttp} from "@/lib/request";
|
||||
|
||||
const http = createHttp(Astro.request.headers);
|
||||
|
||||
const {data} = await http.get<ApiResponse<Archive>>("posts/archives");
|
||||
---
|
||||
|
||||
|
||||
<Layout title="归档" description="">
|
||||
<div class="archive">
|
||||
{
|
||||
data.map((year) => (
|
||||
<div class="archive-year">
|
||||
<h2 class="year-title">
|
||||
<span class="year-badge">{year.year}年</span>
|
||||
<span class="year-count">共 {year.total} 篇</span>
|
||||
</h2>
|
||||
<div>
|
||||
{year.list.map((month) => (
|
||||
<div class="month-group">
|
||||
<h3 class="month-title">{month.month} 月</h3>
|
||||
<ul class="post-list">
|
||||
{month.list.map((post) => (
|
||||
<li class="post-item">
|
||||
<span class="post-date">
|
||||
{post.published_at_display}
|
||||
</span>
|
||||
<a class="post-title" href={`/post/${post.slug}`}>{post.title}</a>
|
||||
<span class="post-cat">{post.category_name}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
</Layout>
|
||||
|
||||
<style>
|
||||
.archive {
|
||||
|
||||
}
|
||||
|
||||
.archive-year {
|
||||
|
||||
}
|
||||
|
||||
.year-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
color: var(--text-primary);
|
||||
font-size: 32px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.year-badge {
|
||||
|
||||
}
|
||||
|
||||
.year-count {
|
||||
font-size: 14px;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.month-group {
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
.month-title {
|
||||
color: #60a5fa;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.post-list {
|
||||
padding: 12px 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.post-item {
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
font-size: 14px;
|
||||
border-bottom: var(--border-secondary);
|
||||
padding: 18px 0;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.post-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.post-date {
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
|
||||
.post-title {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.post-title:hover{
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.post-cat {
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -4,7 +4,6 @@ import "@/styles/github-markdown-reset.css";
|
||||
import "photoswipe/dist/photoswipe.css";
|
||||
|
||||
import Layout from '@/layouts/Layout.astro';
|
||||
import PageHeader from '@/components/PageHeader.astro';
|
||||
import {createHttp} from "@/lib/request.ts";
|
||||
import type {Post} from "@/types";
|
||||
import {processHtmlWithJsdom} from "@/lib/processHtml.ts";
|
||||
@@ -30,51 +29,34 @@ const content = await processHtmlWithJsdom(data.content);
|
||||
const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
||||
---
|
||||
|
||||
<Layout title={data.title} description="">
|
||||
<div class="page-container">
|
||||
<PageHeader />
|
||||
|
||||
<article>
|
||||
<div class="meta">
|
||||
<div class="meta-left">
|
||||
<span>{data.category_name} · {data.category_code.toUpperCase()}</span>
|
||||
<span>{published_at}</span>
|
||||
</div>
|
||||
|
||||
<div class="meta-view-count">{data.view_count} 次阅读</div>
|
||||
<Layout title={data.title} description={data.summary}>
|
||||
<article>
|
||||
<div class="meta">
|
||||
<div class="meta-left">
|
||||
<span>{data.category_name} · {data.category_code.toUpperCase()}</span>
|
||||
<span>{published_at}</span>
|
||||
</div>
|
||||
<h1>{data.title}</h1>
|
||||
|
||||
<p class="summary">{data.summary}</p>
|
||||
<div class="meta-view-count">{data.view_count} 次阅读</div>
|
||||
</div>
|
||||
<h1>{data.title}</h1>
|
||||
|
||||
<div class="divider"></div>
|
||||
<p class="summary">{data.summary}</p>
|
||||
|
||||
<div class="markdown-body" data-color-mode="dark" set:html={content}/>
|
||||
<div class="divider"></div>
|
||||
|
||||
{
|
||||
data.tags.length > 0 &&
|
||||
<div class="tags">
|
||||
{data.tags.map(tag => <span>{tag.name}</span>)}
|
||||
</div>
|
||||
}
|
||||
</article>
|
||||
<div class="markdown-body" data-color-mode="dark" set:html={content}/>
|
||||
|
||||
<footer>
|
||||
<div>© {siteTitle}</div>
|
||||
</footer>
|
||||
</div>
|
||||
{
|
||||
data.tags.length > 0 &&
|
||||
<div class="tags">
|
||||
{data.tags.map(tag => <span>{tag.name}</span>)}
|
||||
</div>
|
||||
}
|
||||
</article>
|
||||
</Layout>
|
||||
|
||||
<style>
|
||||
.page-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
|
||||
article {
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
@@ -139,18 +121,6 @@ const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
||||
border-radius: 20px;
|
||||
padding: 8px 16px;
|
||||
}
|
||||
|
||||
footer{
|
||||
flex-shrink: 0;
|
||||
width: 100%;
|
||||
margin-top: 24px;
|
||||
border-top: var(--border-secondary);
|
||||
height: 66px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: var(--text-tertiary);
|
||||
font-size: 13px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
|
||||
@@ -5,6 +5,7 @@ const site = siteConfig.site
|
||||
|
||||
const staticUrls = [
|
||||
'',
|
||||
'/archive'
|
||||
];
|
||||
|
||||
export const GET: APIRoute = async () => {
|
||||
|
||||
Reference in New Issue
Block a user