feat: 404 page

This commit is contained in:
2026-07-09 16:23:45 +08:00
parent 26ce6ed4ef
commit 540168d30f
3 changed files with 40 additions and 5 deletions

View File

@@ -18,11 +18,16 @@ interface Post {
content: string;
}
const {data} = await http.get<ApiResponse<Post>>(`post/${slug}`);
let data: Post;
try {
const res = await http.get<ApiResponse<Post>>(`post/${slug}`);
data = res.data
} catch (error) {
return Astro.redirect("/404")
}
const content = await highlightHtmlWithJsdom(data.content)
data.published_at = formatDatetime(data.published_at, 'YYYY 年 M 月 D 日')
const published_at = formatDatetime(data.published_at, 'YYYY 年 M 月 D 日')
---
<Layout title={data.title} description={data.summary}>
@@ -43,7 +48,7 @@ data.published_at = formatDatetime(data.published_at, 'YYYY 年 M 月 D 日')
<path d="M12 18h.01"/>
<path d="M16 18h.01"/>
</svg>
{data.published_at}
{published_at}
</div>
<div class="post markdown-body" set:html={content}></div>