Added not-found support for sitesettings
This commit is contained in:
@@ -7,7 +7,11 @@ import type { ArchiveEntries, ContentOption, ResolvedRoute } from '../content/in
|
||||
import type { I18nConfig } from '../i18n/index.js'
|
||||
import type { RobotsRules, SitemapEntry } from '../seo/index.js'
|
||||
|
||||
import { getArchiveEntries, resolveRoute as resolveRouteRaw } from '../content/index.js'
|
||||
import {
|
||||
getArchiveEntries,
|
||||
resolveNotFoundPage,
|
||||
resolveRoute as resolveRouteRaw,
|
||||
} from '../content/index.js'
|
||||
import { buildRobots, buildSitemapEntries } from '../seo/index.js'
|
||||
|
||||
type CreateContentHelpersArgs = {
|
||||
@@ -96,6 +100,20 @@ export function createContentHelpers({
|
||||
},
|
||||
)
|
||||
|
||||
/**
|
||||
* The page assigned as 404 in System Pages (or null → built-in fallback).
|
||||
* For app/not-found.tsx; never throws. Locale comes from the x-locale header
|
||||
* set by createProxy (not-found.tsx receives no params).
|
||||
*/
|
||||
const getNotFoundPage = cache(async (locale: string) => {
|
||||
try {
|
||||
const payload = await getCachedPayload()
|
||||
return await resolveNotFoundPage({ locale, pagesSlug, payload, settingsSlug })
|
||||
} catch {
|
||||
return null // DB unreachable (container build) — fallback view
|
||||
}
|
||||
})
|
||||
|
||||
/** One page of a collection's entries, for an archive listing. */
|
||||
const getEntries = cache(
|
||||
async (
|
||||
@@ -202,8 +220,16 @@ export function createContentHelpers({
|
||||
// Home slug per locale, to exclude the homepage (it's the root, slug []).
|
||||
const settings = (await payload
|
||||
.findGlobal({ slug: settingsSlug as never, depth: 1, locale: 'all' as never })
|
||||
.catch(() => null)) as { homepage?: { id?: number | string; slug?: unknown } } | null
|
||||
.catch(() => null)) as {
|
||||
homepage?: { id?: number | string; slug?: unknown }
|
||||
notFound?: { id?: number | string } | null
|
||||
} | null
|
||||
const homeId = settings?.homepage?.id
|
||||
// The assigned 404 page renders via not-found.tsx, never as its own URL.
|
||||
const notFoundId =
|
||||
settings?.notFound?.id !== undefined && settings.notFound.id !== homeId
|
||||
? settings.notFound.id
|
||||
: undefined
|
||||
|
||||
const EXCLUDED = new Set(['404', '500', 'error', 'not-found'])
|
||||
const params: Array<{ locale: string; slug: string[] } | { slug: string[] }> = []
|
||||
@@ -228,6 +254,7 @@ export function createContentHelpers({
|
||||
}>) {
|
||||
// Draft filter in memory (safe whether or not the collection has drafts).
|
||||
if (raw._status && raw._status !== 'published') {continue}
|
||||
if (notFoundId !== undefined && raw.id === notFoundId) {continue}
|
||||
|
||||
// NOTE: unlike the sitemap, we do NOT skip meta.noindex here. A noindex
|
||||
// page (privacy, cookies, terms) still needs to render — users reach it
|
||||
@@ -286,6 +313,7 @@ export function createContentHelpers({
|
||||
getCachedPayload,
|
||||
getConfiguredLocales,
|
||||
getEntries,
|
||||
getNotFoundPage,
|
||||
getSettings,
|
||||
resolveRoute,
|
||||
robots,
|
||||
|
||||
Reference in New Issue
Block a user