This commit is contained in:
2025-11-30 14:53:14 +08:00
parent 1e6c0c0ab9
commit 32fdaac7db
8 changed files with 122 additions and 81 deletions

View File

@@ -16,7 +16,7 @@ import { cn } from '@/lib/utils'
>
<div class="max-w-md">
<h1 class="mb-4 text-3xl font-medium">404: Page not found</h1>
<p class="prose">Oops! The page you're looking for doesn't exist.</p>
<p class="prose">啊哦,你好像来到了没有知识的荒原~</p>
</div>
<Link
href="/"

29
src/pages/500.astro Normal file
View File

@@ -0,0 +1,29 @@
---
import Breadcrumbs from '@/components/Breadcrumbs.astro'
import Link from '@/components/Link.astro'
import PageHead from '@/components/PageHead.astro'
import { buttonVariants } from '@/components/ui/button'
import Layout from '@/layouts/Layout.astro'
import { cn } from '@/lib/utils'
---
<Layout class="max-w-3xl">
<PageHead slot="head" title="500" />
<Breadcrumbs items={[{ label: 'Error', icon: 'lucide:server-off' }]} />
<section class="flex flex-col items-center justify-center gap-y-4 text-center">
<div class="max-w-md">
<h1 class="mb-4 text-3xl font-medium">500: Something went wrong</h1>
<p class="prose">
服务器爆炸了!如果你能联系到博主的话提醒他一声吧!
</p>
</div>
<Link
href="/"
class={cn(buttonVariants({ variant: 'outline' }), 'flex gap-x-1.5 group')}
>
<span class="transition-transform group-hover:-translate-x-1">&larr;</span>
Go to home page
</Link>
</section>
</Layout>

View File

@@ -42,41 +42,55 @@ export async function getStaticPaths() {
const currentPostId = Astro.params.id
let Content: any = null
let headings
let remoteContent = null
let headings: any[] = []
let remoteContent: any = null
let post: any = null
let authors: any[] = []
let isCurrentSubpost = false
let navigation: any = null
let parentPost: any = null
let hasChildPosts = false
let subpostCount = 0
let tocSections: TOCSection[] = []
let heroImage: any = null
try {
const remote = await fetchRemotePostContent(currentPostId)
if (!remote) {
// return Astro.response(null, {status: 404})
return Astro.rewrite('/404')
}
const remote = await fetchRemotePostContent(currentPostId)
if(!remote) {
// return Astro.response(null, {status: 404})
return Astro.rewrite("/404")
remoteContent = renderRemoteBlockMap(remote.blockMap, remote.rootId)
headings = remoteContent?.headings ?? []
post = remote.post
authors = await parseAuthors(post?.authors ?? [])
isCurrentSubpost = isSubpost(currentPostId)
navigation = await getAdjacentPosts(currentPostId)
parentPost = isCurrentSubpost ? await getParentPost(currentPostId) : null
hasChildPosts = await hasSubposts(currentPostId)
subpostCount = !isCurrentSubpost
? await getSubpostCount(currentPostId)
: 0
tocSections = remoteContent
? remoteContent.headings.length > 0
? [
{
type: 'parent',
title: 'Overview',
headings: remoteContent.headings,
},
]
: []
: await getTOCSections(currentPostId)
heroImage = post?.data?.banner
} catch (error) {
console.error('blog page render failed:', error)
return Astro.rewrite('/500')
}
remoteContent = remote ? renderRemoteBlockMap(remote.blockMap, remote.post.id) : null
headings = remoteContent?.headings ?? []
const post = remote?.post
const authors = await parseAuthors(post?.authors ?? [])
const isCurrentSubpost = isSubpost(currentPostId)
const navigation = await getAdjacentPosts(currentPostId)
const parentPost = isCurrentSubpost ? await getParentPost(currentPostId) : null
const hasChildPosts = await hasSubposts(currentPostId)
const subpostCount = !isCurrentSubpost
? await getSubpostCount(currentPostId)
: 0
const tocSections: TOCSection[] = remoteContent
? remoteContent.headings.length > 0
? [
{
type: 'parent',
title: 'Overview',
headings: remoteContent.headings,
},
]
: []
: await getTOCSections(currentPostId)
const heroImage = post?.data?.banner
export const prerender = false;
---

View File

@@ -35,7 +35,6 @@ const page = await fetch(`https://notion-api.nvme0n1p.dev/v2/posts/?page=${nowPa
lastPage: totalPages,
};
});
console.log(page);
// fetch page
if(page.lastPage < page.currentPage) {
console.log("redirect to 404")