From 104cdbfd4cc19d9a25cb6f91b39672ba59288473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Thu, 22 Oct 2026 17:20:37 +0200 Subject: [PATCH] SEO: use construction/visibility pathOf (identical to security-perf branch) for the sitemap filter Co-Authored-By: Claude Opus 5.5 --- src/modules/construction/visibility.ts | 10 ++++++++++ src/modules/frontend/createContentHelpers.ts | 15 +++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 src/modules/construction/visibility.ts diff --git a/src/modules/construction/visibility.ts b/src/modules/construction/visibility.ts new file mode 100644 index 0000000..cdad4aa --- /dev/null +++ b/src/modules/construction/visibility.ts @@ -0,0 +1,10 @@ +/** + * Is this public page path served right now? createContentHelpers builds it from + * Site Settings → Under construction (`isPathVisible`), so the Markdown, MCP and + * search routes hide exactly what the page route hides. Paths are page paths as + * a visitor sees them ('/pl/o-nas', or '/o-nas' on a single-language site). + */ +export type PathVisibility = (path: string, locale: string) => boolean | Promise + +/** Pathname of a result URL (absolute or relative), for a PathVisibility check. */ +export const pathOf = (url: string): string => new URL(url, 'http://localhost').pathname diff --git a/src/modules/frontend/createContentHelpers.ts b/src/modules/frontend/createContentHelpers.ts index 9ac9eae..8800809 100644 --- a/src/modules/frontend/createContentHelpers.ts +++ b/src/modules/frontend/createContentHelpers.ts @@ -16,6 +16,7 @@ import type { PageMetadata, RobotsOptions, RobotsRules, SitemapEntry, SitemapRou import { getAnalyticsConfig } from '../analytics/getAnalyticsConfig.js' import { getConsentTexts } from '../consent/getConsentTexts.js' import { normalizePath } 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' @@ -35,15 +36,6 @@ 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 @@ -753,7 +745,10 @@ 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. + * 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 => { if (!i18n || !underConstructionSeo) {return null}