SEO/GEO/GSC: sitemap index + caching, Search & AI settings, getRobots

- Sitemap: batched reads (500), published-only where, field select; sitemap
  index over maxUrls (default 10k) with ?part=N; Cache-Control; in-process
  memo; runtime errors → 503 Retry-After (empty urlset only during next build)
- Site Settings → Search & AI tab (seo.searchSettings: false removes it):
  Google/Bing/Yandex verification (paste code or whole meta tag) added to
  page metadata; AI crawler policy + per-bot exceptions; llms.txt note
- buildRobots aiBotRules; getRobots helper reads the panel; more AI agents
- Under construction: sitemap and llms.txt list only open pages
- collectSiteIndex: no silent 1000 cap; llms routes send Cache-Control
- IndexNow: nothing sent with IPAL_NOINDEX
- Unknown route metadata is noindex
- Tests (unit + SQLite integration) and docs/seo.md

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-22 17:09:01 +02:00
co-authored by Claude Opus 5.5
parent 12fbd424a5
commit 94e563055f
23 changed files with 1144 additions and 67 deletions
+73 -6
View File
@@ -15,6 +15,7 @@ import type { PageMetadata, RobotsOptions, RobotsRules, SitemapEntry, SitemapSty
import { getAnalyticsConfig } from '../analytics/getAnalyticsConfig.js'
import { getConsentTexts } from '../consent/getConsentTexts.js'
import { normalizePath } from '../construction/logic.js'
import { createMarkdownRoute } from '../content/createMarkdownRenderer.js'
import { getArchiveEntries, resolveRoute as resolveRouteRaw } from '../content/index.js'
import { MARKDOWN_PREFIX, markdownHref } from '../content/markdownNegotiation.js'
@@ -30,9 +31,19 @@ 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 { robotsOptionsFrom } from '../seo/searchSettings.js'
import { type ThemeConfig, themeConfigFrom } from '../theme/theme.js'
import { getTurnstileConfig } from '../turnstile/config.js'
/** Path of an absolute or relative URL: 'https://acme.pl/pl/o-nas' → '/pl/o-nas'. */
const pathOf = (url: string): string => {
try {
return new URL(url, 'http://local').pathname
} catch {
return url
}
}
type CreateContentHelpersArgs = {
/**
* Absolute site origin for sitemap/robots URLs. Falls back to
@@ -424,7 +435,7 @@ export function createContentHelpers({
)
}
try {
return await buildSitemapEntries({
const entries = await buildSitemapEntries({
baseUrl: origin,
config: i18n,
content,
@@ -433,10 +444,19 @@ export function createContentHelpers({
payload: await getCachedPayload(),
settingsSlug,
})
// Under construction: list only the pages visitors can still open — the
// rest redirect to the homepage notice, which crawlers would index.
const open = await constructionPaths()
if (!open) {return entries}
const allowed = new Set(open.map(normalizePath))
return entries.filter((e) => allowed.has(normalizePath(pathOf(e.url))))
} catch (error) {
// DB unreachable (typically a container build with no DB network) — return
// an empty sitemap instead of failing the build. Runtime regeneration will
// produce the real one once the DB is reachable. See dynamic='force-dynamic'.
// At runtime a failure is an error (the sitemap route answers 503, so
// crawlers retry) — an empty sitemap would read as "no pages".
if (process.env.NEXT_PHASE !== 'phase-production-build') {throw error}
// DB unreachable during `next build` (container with no DB network) —
// return an empty sitemap instead of failing the build. Runtime regeneration
// produces the real one. See dynamic='force-dynamic'.
console.warn(
'[ipal] sitemap: could not reach the database, returning empty entries ' +
"(add `export const dynamic = 'force-dynamic'` to app/sitemap.ts to " +
@@ -457,6 +477,37 @@ export function createContentHelpers({
*/
const robots = (): RobotsRules => buildRobots({ ...robotsOptions, baseUrl: origin })
/**
* `robots` plus what editors set in Site Settings → Search & AI (AI bot policy
* and per-bot exceptions), read per request. Use it instead of `robots` to
* let the panel manage AI crawlers:
*
* ```ts
* // app/robots.ts
* export { getRobots as default } from '@/lib/content'
* export const dynamic = 'force-dynamic'
* ```
*
* Database unreachable → the options from code, as `robots` returns.
*/
const getRobots = async (): Promise<RobotsRules> => {
let fromPanel: ReturnType<typeof robotsOptionsFrom> = {}
try {
const payload = await getCachedPayload()
fromPanel = robotsOptionsFrom(
(await payload.findGlobal({ slug: settingsSlug as never, depth: 0 })) as Record<string, unknown>,
)
} catch {
// keep the code options
}
return buildRobots({
...robotsOptions,
...fromPanel,
aiBotRules: [...(robotsOptions?.aiBotRules ?? []), ...(fromPanel.aiBotRules ?? [])],
baseUrl: origin,
})
}
/**
* Next.js generateStaticParams for the [[...slug]] route (or
* [locale]/[[...slug]]). Returns every routable page as a params object, so
@@ -680,6 +731,21 @@ export function createContentHelpers({
}
})
/**
* While Site Settings → Under construction is on: the paths still open (every
* language), which the sitemap and llms.txt list instead of everything.
* null when the site is open or the setting can't be read.
*/
const constructionPaths = async (): Promise<null | string[]> => {
if (!i18n) {return null}
try {
const mode = await getConstructionMode(i18n.defaultLocale)
return mode.enabled ? mode.allowedPaths : null
} catch {
return null
}
}
// ── Layout ────────────────────────────────────────────────────────────────
/** Notifications → form texts in this locale (BuilderForm / RenderForm `texts`). */
const getFormTexts = cache(async (locale: string): Promise<FormNotificationTexts> =>
@@ -730,8 +796,8 @@ export function createContentHelpers({
let value: T | undefined
return () => (value ??= make())
}
const llms = lazy(() => createLlmsTxtRoute({ baseUrl: origin, config: needI18n('llmsRoute'), content, getCachedPayload, pagesSlug, settingsSlug, summaryField }))
const llmsFull = lazy(() => createLlmsTxtRoute({ baseUrl: origin, config: needI18n('llmsFullRoute'), content, full: true, getCachedPayload, pagesSlug, settingsSlug, summaryField }))
const llms = lazy(() => createLlmsTxtRoute({ baseUrl: origin, config: needI18n('llmsRoute'), content, getCachedPayload, getIncludedPaths: constructionPaths, pagesSlug, settingsSlug, summaryField }))
const llmsFull = lazy(() => createLlmsTxtRoute({ baseUrl: origin, config: needI18n('llmsFullRoute'), content, full: true, getCachedPayload, getIncludedPaths: constructionPaths, pagesSlug, settingsSlug, summaryField }))
const md = lazy(() => createMarkdownRoute({ baseUrl: origin || undefined, collection: pagesSlug, config: i18n, content, getCachedPayload, settingsSlug, ...markdownOptions }))
const mcp = lazy(() => createMcpRoute({ baseUrl: origin, collection: pagesSlug, config: needI18n('mcpRoute'), content, getCachedPayload, settingsSlug, summaryField, ...mcpOptions }))
const health = lazy(() => createHealthRoute({ collection: pagesSlug, getCachedPayload }))
@@ -766,6 +832,7 @@ export function createContentHelpers({
getLinkOptions,
getNotFoundPage,
getPageJsonLd,
getRobots,
getSettings,
getSiteShell,
getSystemLinks,