From 540168d30f291414441b287c684b9014041f7775 Mon Sep 17 00:00:00 2001 From: xy <10816187@qq.com> Date: Thu, 9 Jul 2026 16:23:45 +0800 Subject: [PATCH] feat: 404 page --- src/pages/404.astro | 30 ++++++++++++++++++++++++++++++ src/pages/index.astro | 2 +- src/pages/posts/[...slug].astro | 13 +++++++++---- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/pages/404.astro diff --git a/src/pages/404.astro b/src/pages/404.astro new file mode 100644 index 0000000..5257102 --- /dev/null +++ b/src/pages/404.astro @@ -0,0 +1,30 @@ +--- +import Layout from "@/layouts/Layout.astro"; +--- + + +
+

404 Not Found

+ 返回首页 +
+
+ + diff --git a/src/pages/index.astro b/src/pages/index.astro index 228b608..edf7c68 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -95,7 +95,7 @@ list.map((post) => { color: #6b7280; } - @media (max-width: 640px) { + @media (max-width: 768px) { .posts { gap: 12px; } diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 9ba48aa..4794705 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -18,11 +18,16 @@ interface Post { content: string; } -const {data} = await http.get>(`post/${slug}`); +let data: Post; +try { + const res = await http.get>(`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 日') --- @@ -43,7 +48,7 @@ data.published_at = formatDatetime(data.published_at, 'YYYY 年 M 月 D 日') - {data.published_at} + {published_at}