Theme switcher, table of contents, missing-page redirect, form placeholders and time field; audit and revalidate fixes

- buildRevalidateHook skips outside Next (no NEXT_RUNTIME) and with context.disableRevalidate
- BuilderForm focuses only on a real step change (no scroll to the form on remount)
- mediaImageProps: placeholder colour only for JPEG (placeholderColor); hook stores no colour for transparent images
- buildLinkField: interface name per shape (CmsLink, CmsLinkPlain, CmsLinkNoLabel) + interfaceName option
- Cookie Settings: buttons.save -> buttons.savePreferences (Mongoose reserved name)
- ThemeScript, ThemeSwitcher, useTheme; Site Settings defaultTheme 'system' + themeToggleLabel; Turnstile follows page theme
- extractHeadings, RenderRichText headingIds, TableOfContents, buildTableOfContentsField
- createPageRoute onMissing: 'redirectHome'
- Form builder: localized placeholder on text/email/textarea/number, new time field
- ipal-audit: no false positive for object keys between JSX elements; /md route not reported as dynamic

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-19 21:32:40 +02:00
co-authored by Claude Opus 5.5
parent 23e033d7d7
commit faa4ad679c
55 changed files with 1298 additions and 58 deletions
+9
View File
@@ -10,6 +10,7 @@ import { CookieBanner } from '../consent/CookieBanner.js'
import { CookieButton } from '../consent/CookieButton.js'
import { JsonLdGraph } from '../seo/JsonLdGraph.js'
import { MediaPreconnect } from '../storage/MediaPreconnect.js'
import { ThemeScript } from '../theme/ThemeScript.js'
import { TurnstileProvider } from '../turnstile/TurnstileProvider.js'
export type SiteProvidersProps = {
@@ -30,6 +31,12 @@ export type SiteProvidersProps = {
preconnect?: boolean
/** getSiteShell(locale) from lib/content. */
shell: SiteShell
/**
* Light / dark theme from Site Settings → Theme: renders <ThemeScript> first,
* so the theme is on <html> before the first paint. Put <SiteProviders> first in
* <body> and add `suppressHydrationWarning` to <html>. Default false.
*/
theme?: boolean
}
/**
@@ -58,9 +65,11 @@ export function SiteProviders({
logEndpoint,
preconnect = true,
shell,
theme = false,
}: SiteProvidersProps) {
return (
<>
{theme ? <ThemeScript {...shell.theme} /> : null}
{preconnect ? <MediaPreconnect /> : null}
<JsonLdGraph schemas={[...shell.jsonLd, ...jsonLd]} />
<ConsentProvider cookieMap={cookieMap} logEndpoint={logEndpoint} texts={shell.consent}>
@@ -30,6 +30,7 @@ import { buildWebSiteJsonLd } from '../seo/buildWebSiteJsonLd.js'
import { buildArticleJsonLd, buildBreadcrumbJsonLd, buildFaqJsonLd, buildRobots, buildSitemapEntries, createManifestHandler, createPageMetadata, createSitemapRouteHandler } from '../seo/index.js'
import { createIndexNowKeyRoute } from '../seo/indexNow.js'
import { createLlmsTxtRoute } from '../seo/routeHandlers.js'
import { type ThemeConfig, themeConfigFrom } from '../theme/theme.js'
import { getTurnstileConfig } from '../turnstile/config.js'
type CreateContentHelpersArgs = {
@@ -717,6 +718,7 @@ export function createContentHelpers({
formTexts,
jsonLd: jsonLd.map(({ '@context': _context, ...node }) => node),
settings: settings ?? {},
theme: themeConfigFrom(settings),
turnstileSiteKey: turnstile.siteKey,
}
})
@@ -794,6 +796,8 @@ export type SiteShell = {
/** Site-wide nodes (WebSite, Organization…) for <JsonLdGraph>. */
jsonLd: Record<string, unknown>[]
settings: Record<string, unknown>
/** Site Settings → Theme, for <ThemeScript> / <SiteProviders theme> and <ThemeSwitcher label>. */
theme: ThemeConfig
turnstileSiteKey: null | string
}
+25 -3
View File
@@ -9,7 +9,7 @@ import { constructionNoticeHref, isPathAllowed } from '../construction/logic.js'
import { LocaleView } from '../pages/LocaleView.js'
import { JsonLdGraph } from '../seo/JsonLdGraph.js'
type Helpers = Partial<Pick<ContentHelpers, 'getConstructionMode'>> & Pick<
type Helpers = Partial<Pick<ContentHelpers, 'getConstructionMode' | 'getSystemLinks'>> & Pick<
ContentHelpers,
'generatePageMetadata' | 'generateStaticParams' | 'getConfiguredLocales' | 'getNotFoundPage' | 'getPageJsonLd' | 'i18n' | 'resolvePageRedirect' | 'resolveRoute'
>
@@ -31,6 +31,14 @@ export type PageRouteOptions = {
layoutField?: string
/** `notFound` from 'next/navigation' — injected, the plugin doesn't import next/* on the server. */
notFound: () => never
/**
* An address with no page (and no old-slug redirect):
* - 'notFound' (default) — the 404 page;
* - 'redirectHome' — 307 to the homepage in the same language (System Pages → Homepage;
* needs `redirect`). No homepage assigned, or the homepage itself missing → 404;
* - a function — your own decision, e.g. `({ locale }) => redirect(\`/${locale}/kontakt\`)`.
*/
onMissing?: 'notFound' | 'redirectHome' | ((ctx: { locale: string; segments: string[] }) => never | Promise<never>)
/** `permanentRedirect` from 'next/navigation' (308 for an old slug). */
permanentRedirect: (url: string) => never
/**
@@ -67,7 +75,10 @@ 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, redirect, render } = options
const { blockProps, blocks, jsonLd = true, layoutField = 'layout', notFound, onMissing = 'notFound', permanentRedirect, redirect, render } = options
if (onMissing === 'redirectHome' && !redirect) {
throw new Error("[ipal] createPageRoute: onMissing: 'redirectHome' needs `redirect` from 'next/navigation'.")
}
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.')}
@@ -79,6 +90,16 @@ export function createPageRoute(helpers: Helpers, options: PageRouteOptions) {
return helpers.generatePageMetadata(localeOf(locale), slug)
}
async function missing(locale: string, segments: string[]): Promise<never> {
if (typeof onMissing === 'function') {return onMissing({ locale, segments })}
// segments.length: the homepage itself is missing — redirecting to it would loop.
if (onMissing === 'redirectHome' && redirect && helpers.getSystemLinks && segments.length) {
const [home] = await helpers.getSystemLinks(locale, ['homepage'])
if (home?.href) {return redirect(home.href)}
}
return notFound()
}
async function Page({ params }: PageArgs) {
const { slug, locale: param } = await params
const locale = localeOf(param)
@@ -93,7 +114,8 @@ export function createPageRoute(helpers: Helpers, options: PageRouteOptions) {
const route = await helpers.resolveRoute(locale, segments, 1)
if (!route) {
const target = await helpers.resolvePageRedirect(locale, segments)
return target ? permanentRedirect(target) : notFound()
if (target) {return permanentRedirect(target)}
return missing(locale, segments)
}
const doc = route.doc
const extra = blockProps ? await blockProps({ doc, locale }) : {}