Merge SEO, GEO and Search Console track
Conflict in createContentHelpers.ts resolved by keeping both: isPathVisible (per-path, security track) and constructionPaths (per-list, SEO track). Co-Authored-By: Claude Opus 5.5 <[email protected]> # Conflicts: # src/modules/frontend/createContentHelpers.ts
This commit is contained in:
@@ -12,11 +12,12 @@ import type { I18nConfig } from '../i18n/index.js'
|
||||
import type { LinkValue, NavItem, ResolvedLink, ResolveLinkHrefOptions, SystemLink } from '../links/index.js'
|
||||
import type { CreateMcpRouteArgs } from '../mcp/createMcpRoute.js'
|
||||
import type { FormNotificationTexts } from '../notifications/types.js'
|
||||
import type { PageMetadata, RobotsOptions, RobotsRules, SitemapEntry, SitemapStyleOptions } from '../seo/index.js'
|
||||
import type { PageMetadata, RobotsOptions, RobotsRules, SitemapEntry, SitemapRouteOptions, SitemapStyleOptions } from '../seo/index.js'
|
||||
|
||||
import { getAnalyticsConfig } from '../analytics/getAnalyticsConfig.js'
|
||||
import { getConsentTexts } from '../consent/getConsentTexts.js'
|
||||
import { isPathVisibleIn } from '../construction/logic.js'
|
||||
import { isPathAllowed, isPathVisibleIn } from '../construction/logic.js'
|
||||
import { pathOf } from '../construction/visibility.js'
|
||||
import { createMarkdownRoute } from '../content/createMarkdownRenderer.js'
|
||||
import { getArchiveEntries, resolveRoute as resolveRouteRaw } from '../content/index.js'
|
||||
import { MARKDOWN_PREFIX, markdownHref } from '../content/markdownNegotiation.js'
|
||||
@@ -32,6 +33,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 { robotsOptionsFrom } from '../seo/searchSettings.js'
|
||||
import { type ThemeConfig, themeConfigFrom } from '../theme/theme.js'
|
||||
import { getTurnstileConfig } from '../turnstile/config.js'
|
||||
|
||||
@@ -93,8 +95,19 @@ type CreateContentHelpersArgs = {
|
||||
* LocalBusiness from the Company global); `false` = none.
|
||||
*/
|
||||
siteJsonLd?: ((ctx: { baseUrl: string; locale: string; settings: Record<string, unknown> }) => Promise<Record<string, unknown>[]> | Record<string, unknown>[]) | false
|
||||
/**
|
||||
* Last word on the sitemap: gets the plugin's entries (after the construction
|
||||
* filter) and returns the list to publish — add URLs from your own routes,
|
||||
* drop or reorder some, set priority. Used by `sitemap` and `sitemapRoute`.
|
||||
*/
|
||||
sitemapEntries?: (entries: SitemapEntry[]) => Promise<SitemapEntry[]> | SitemapEntry[]
|
||||
/** Image URLs of a document for the sitemap (Google Images). Default: its SEO share image. */
|
||||
sitemapImages?: (doc: Record<string, unknown>) => (null | string | undefined)[]
|
||||
/**
|
||||
* `sitemapRoute` behaviour: `maxUrls` (split into an index, default 10 000),
|
||||
* `cacheControl` (string or false), `memoSeconds` (default 300, 0 = off).
|
||||
*/
|
||||
sitemapOptions?: Pick<SitemapRouteOptions, 'cacheControl' | 'maxUrls' | 'memoSeconds'>
|
||||
/**
|
||||
* Browser look of `sitemapRoute` (/sitemap.xml). Default: built-in style,
|
||||
* header "XML Sitemap", credit "Technology by Intecion.com". `false` = raw XML.
|
||||
@@ -102,6 +115,11 @@ type CreateContentHelpersArgs = {
|
||||
sitemapStyle?: false | SitemapStyleOptions
|
||||
/** Field with the AI summary (buildSummaryField) — llms.txt and MCP prefer it. */
|
||||
summaryField?: string
|
||||
/**
|
||||
* While Site Settings → Under construction is on, the sitemap and llms.txt
|
||||
* list only the pages still open. Default true; false lists everything.
|
||||
*/
|
||||
underConstructionSeo?: boolean
|
||||
}
|
||||
|
||||
/** What an entry's own JSON-LD builder gets (PageJsonLdOptions.entries). */
|
||||
@@ -180,9 +198,12 @@ export function createContentHelpers({
|
||||
settingsDepth = 1,
|
||||
settingsSlug = 'site-settings',
|
||||
siteJsonLd,
|
||||
sitemapEntries: transformSitemap,
|
||||
sitemapImages,
|
||||
sitemapOptions,
|
||||
sitemapStyle,
|
||||
summaryField,
|
||||
underConstructionSeo = true,
|
||||
}: CreateContentHelpersArgs) {
|
||||
const origin = baseUrl ?? process.env.NEXT_PUBLIC_SERVER_URL ?? ''
|
||||
const getCachedPayload = cache(
|
||||
@@ -438,7 +459,7 @@ export function createContentHelpers({
|
||||
)
|
||||
}
|
||||
try {
|
||||
return await buildSitemapEntries({
|
||||
const entries = await buildSitemapEntries({
|
||||
baseUrl: origin,
|
||||
config: i18n,
|
||||
content,
|
||||
@@ -447,10 +468,20 @@ 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.
|
||||
// Same check as isPathVisibleIn(mode, pathOf(url)) (security-perf branch), with the
|
||||
// mode read once for the whole list.
|
||||
const open = await constructionPaths()
|
||||
const visible = open ? entries.filter((e) => isPathAllowed(pathOf(e.url), open)) : entries
|
||||
return transformSitemap ? await transformSitemap(visible) : visible
|
||||
} 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 " +
|
||||
@@ -471,6 +502,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
|
||||
@@ -599,7 +661,7 @@ export function createContentHelpers({
|
||||
* export { sitemapRoute as GET } from '@/lib/content'
|
||||
* export const dynamic = 'force-dynamic'
|
||||
*/
|
||||
const sitemapRoute = createSitemapRouteHandler(sitemap, { style: sitemapStyle ?? {} })
|
||||
const sitemapRoute = createSitemapRouteHandler(sitemap, { ...sitemapOptions, style: sitemapStyle ?? {} })
|
||||
|
||||
const needI18n = (what: string): I18nConfig => {
|
||||
if (!i18n) {throw new Error(`[ipal] createContentHelpers: pass \`i18n\` to use ${what}.`)}
|
||||
@@ -713,6 +775,24 @@ export function createContentHelpers({
|
||||
return isPathVisibleIn(await mode, path)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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. Same rule as
|
||||
* `isPathVisible`, but resolved ONCE per list: the sitemap may hold tens of
|
||||
* thousands of URLs, and in a route handler React `cache` doesn't dedupe a
|
||||
* per-URL settings read.
|
||||
*/
|
||||
const constructionPaths = async (): Promise<null | string[]> => {
|
||||
if (!i18n || !underConstructionSeo) {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> =>
|
||||
@@ -763,8 +843,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, isPathVisible, settingsSlug, ...markdownOptions }))
|
||||
const mcp = lazy(() => createMcpRoute({ baseUrl: origin, collection: pagesSlug, config: needI18n('mcpRoute'), content, getCachedPayload, isPathVisible, settingsSlug, summaryField, ...mcpOptions }))
|
||||
const health = lazy(() => createHealthRoute({ collection: pagesSlug, getCachedPayload }))
|
||||
@@ -799,6 +879,7 @@ export function createContentHelpers({
|
||||
getLinkOptions,
|
||||
getNotFoundPage,
|
||||
getPageJsonLd,
|
||||
getRobots,
|
||||
getSettings,
|
||||
getSiteShell,
|
||||
getSystemLinks,
|
||||
|
||||
Reference in New Issue
Block a user