Fixed notfound headers, r2storage
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import React from 'react'
|
||||
|
||||
import { RenderBlocks } from 'ipal-kit/rsc'
|
||||
import { LocaleView } from 'ipal-kit/client'
|
||||
|
||||
import { i18nConfig } from '@/i18n.config'
|
||||
import { blockRegistry } from '@/blocks/registry'
|
||||
import { getConfiguredLocales, getNotFoundPage } from '@/lib/content'
|
||||
|
||||
/**
|
||||
* 404 view. The editor picks which page plays the 404 role in
|
||||
* Site Settings → System Pages → "404 (Not Found)" — a dedicated page or the
|
||||
* homepage — or leaves it empty → the fallback below.
|
||||
*
|
||||
* not-found.tsx receives no params, and reading headers() here would turn the
|
||||
* SSG/ISR site dynamic ("Page changed from static to dynamic at runtime").
|
||||
* So: render the 404 page for EVERY locale on the server (DB reads only — stays
|
||||
* static) and let <LocaleView> pick the one from the URL (/en/... → en).
|
||||
* Next still answers HTTP 404.
|
||||
*/
|
||||
export default async function NotFound() {
|
||||
const locales = await getConfiguredLocales()
|
||||
|
||||
const views = Object.fromEntries(
|
||||
await Promise.all(
|
||||
locales.map(async (locale) => {
|
||||
const page = (await getNotFoundPage(locale)) as { layout?: unknown[] } | null
|
||||
const view = page?.layout?.length ? (
|
||||
<RenderBlocks
|
||||
blocks={page.layout as never}
|
||||
components={blockRegistry}
|
||||
enhanceProps={() => ({ locale })}
|
||||
/>
|
||||
) : null
|
||||
return [locale, view] as const
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
// No 404 page assigned in any locale (or DB unreachable during build):
|
||||
// the project's own minimal view — style it, keep it text-free or panel-driven.
|
||||
if (Object.values(views).every((v) => v === null)) {
|
||||
return (
|
||||
<main className="container py-24 text-center">
|
||||
<h1 className="text-6xl font-bold">404</h1>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
return <LocaleView views={views} defaultLocale={i18nConfig.defaultLocale} />
|
||||
}
|
||||
Reference in New Issue
Block a user