diff --git a/src/components/Navbar.astro b/src/components/Navbar.astro index 5b447d7..f8c5d4e 100644 --- a/src/components/Navbar.astro +++ b/src/components/Navbar.astro @@ -9,7 +9,8 @@ const items: MenuItem[] = [ { label: "情报", children: [ { href: "/posts", label: "记录" }, - { href: "/events", label: "活动" } + { href: "/events", label: "活动" }, + { href: "/moments", label: "回忆" } ] } ]; diff --git a/src/pages/404.astro b/src/pages/404.astro new file mode 100644 index 0000000..10f8a3a --- /dev/null +++ b/src/pages/404.astro @@ -0,0 +1,15 @@ +--- +import RootLayout from "../layouts/RootLayout.astro"; +--- + + + + + 404 + Not Found + + The resource you want to access was not found. + Back to homepage + + + diff --git a/src/pages/moments.astro b/src/pages/moments.astro new file mode 100644 index 0000000..b510003 --- /dev/null +++ b/src/pages/moments.astro @@ -0,0 +1,17 @@ +--- +import RootLayout from "../layouts/RootLayout.astro"; +--- + + + + + + diff --git a/src/pages/posts/[slug].astro b/src/pages/posts/[slug].astro index ad59f0a..7ad9c2e 100644 --- a/src/pages/posts/[slug].astro +++ b/src/pages/posts/[slug].astro @@ -6,6 +6,7 @@ import Media from "../../components/posts/Media"; import { POST_TYPES } from "../../scripts/consts"; import { graphQuery } from "../../scripts/requests"; import { DocumentRenderer } from "@keystone-6/document-renderer"; +import { navigate } from "astro:transitions/client"; export const prerender = false; @@ -51,33 +52,37 @@ const { post } = ( }, ) ).data; + +if (!post) { + return Astro.redirect("/404"); +} --- - + { - post.cover && ( + post?.cover && ( - + ) } - {post.title} - {post.description ?? "No description"} + {post?.title} + {post?.description ?? "No description"} { - post.assets?.length > 0 && ( + post?.assets?.length > 0 && ( - + ) } - + @@ -88,21 +93,21 @@ const { post } = ( 作者 - {post.author?.name ?? "佚名"} + {post?.author?.name ?? "佚名"} 类型 - {POST_TYPES[post.type as unknown as string]} + {POST_TYPES[post?.type as unknown as string]} 分类 { - post.categories?.map((category: any) => ( - - {category.name} + post?.categories?.map((category: any) => ( + + {category?.name} )) } @@ -112,9 +117,9 @@ const { post } = ( 标签 { - post.tags?.map((tag: any) => ( - - {tag.name} + post?.tags?.map((tag: any) => ( + + {tag?.name} )) } @@ -122,7 +127,7 @@ const { post } = ( 发布于 - {new Date(post.createdAt).toLocaleString()} + {new Date(post?.createdAt).toLocaleString()}
The resource you want to access was not found.
{post.description ?? "No description"}
{post?.description ?? "No description"}