Under construction mode (developer tool)
Site Settings -> Under construction: a switch, 'Pages still available' and notice texts. When on, only the homepage and the chosen pages open (every language); other addresses redirect to the homepage with the notice (createPageRoute redirect option), and <ConstructionNotice> cancels clicks on links to blocked pages and shows the notice. getConstructionMode(locale). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -5,10 +5,11 @@ import type { ResolvedRoute } from '../content/index.js'
|
||||
import type { ContentHelpers, PageJsonLdOptions } from './createContentHelpers.js'
|
||||
|
||||
import { RenderBlocks } from '../blocks/RenderBlocks.js'
|
||||
import { constructionNoticeHref, isPathAllowed } from '../construction/logic.js'
|
||||
import { LocaleView } from '../pages/LocaleView.js'
|
||||
import { JsonLdGraph } from '../seo/JsonLdGraph.js'
|
||||
|
||||
type Helpers = Pick<
|
||||
type Helpers = Partial<Pick<ContentHelpers, 'getConstructionMode'>> & Pick<
|
||||
ContentHelpers,
|
||||
'generatePageMetadata' | 'generateStaticParams' | 'getConfiguredLocales' | 'getNotFoundPage' | 'getPageJsonLd' | 'i18n' | 'resolvePageRedirect' | 'resolveRoute'
|
||||
>
|
||||
@@ -28,6 +29,11 @@ export type PageRouteOptions = {
|
||||
notFound: () => never
|
||||
/** `permanentRedirect` from 'next/navigation' (308 for an old slug). */
|
||||
permanentRedirect: (url: string) => never
|
||||
/**
|
||||
* `redirect` from 'next/navigation' — enables Site Settings → Under construction:
|
||||
* pages that aren't available (and unknown addresses) go to the homepage with the notice.
|
||||
*/
|
||||
redirect?: (url: string) => never
|
||||
/**
|
||||
* Render a route yourself — an archive listing, a blog entry template.
|
||||
* Return undefined to keep the default (the document's blocks).
|
||||
@@ -57,7 +63,7 @@ type PageArgs = { params: Promise<{ locale?: string; slug?: string[] }> }
|
||||
* yourself with the same helpers (PROGRAMISTA §2.8) — nothing here is required.
|
||||
*/
|
||||
export function createPageRoute(helpers: Helpers, options: PageRouteOptions) {
|
||||
const { blockProps, blocks, jsonLd = true, layoutField = 'layout', notFound, permanentRedirect, render } = options
|
||||
const { blockProps, blocks, jsonLd = true, layoutField = 'layout', notFound, permanentRedirect, redirect, render } = options
|
||||
const localeOf = (locale: string | undefined) => {
|
||||
const l = locale ?? helpers.i18n?.defaultLocale
|
||||
if (!l) {throw new Error('[ipal] createPageRoute: no locale param and no i18n.defaultLocale in createContentHelpers.')}
|
||||
@@ -73,6 +79,13 @@ export function createPageRoute(helpers: Helpers, options: PageRouteOptions) {
|
||||
const { slug, locale: param } = await params
|
||||
const locale = localeOf(param)
|
||||
const segments = slug ?? []
|
||||
// Under construction: anything but the homepage and the chosen pages → homepage + notice
|
||||
if (redirect && helpers.getConstructionMode) {
|
||||
const construction = await helpers.getConstructionMode(locale)
|
||||
const multilingual = (helpers.i18n?.locales.length ?? 0) > 1
|
||||
const path = `/${[...(multilingual ? [locale] : []), ...segments].join('/')}`
|
||||
if (construction.enabled && !isPathAllowed(path, construction.allowedPaths)) {return redirect(constructionNoticeHref(construction.homePath))}
|
||||
}
|
||||
const route = await helpers.resolveRoute(locale, segments, 1)
|
||||
if (!route) {
|
||||
const target = await helpers.resolvePageRedirect(locale, segments)
|
||||
|
||||
Reference in New Issue
Block a user