feat: noindex for declared and signed-in routes

- app plugin seo-route-robots: a page whose meta sets requiresAuth: true
  gets robots noindex, nofollow, a page with seo.robots gets its value,
  a path under seo.noindexRoutes gets noindex, nofollow; meta tag above
  the CMS head entry and X-Robots-Tag during SSR, never on staging
- requiresAuth and seo added to Nuxt's page meta extraction keys
- playground /konto, /szkic and /prywatne with their smoke lines
This commit is contained in:
Jakub Zych
2026-11-04 11:49:14 +01:00
parent b4680af0e3
commit 9cc2cda924
9 changed files with 143 additions and 1 deletions

25
lib/routes.ts Normal file
View File

@@ -0,0 +1,25 @@
// The routes the layer tells the CMS about (D-33) and compares with it at
// server start (D-20c). Built at build time from the resolved pages, whose
// meta carries requiresAuth and seo (the module adds both to Nuxt's page
// meta extraction keys), and written into the server template #seo-routes
// for the route report and the drift check. Pure TypeScript, so
// `node --test` drives it.
/** True when a robots value keeps the page out of the index. */
export const robotsNoindex = (robots: unknown) => typeof robots === 'string' && /(^|[\s,])(noindex|none)($|[\s,])/i.test(robots)
/**
* The robots value a page asks for through its meta: seo.robots when set,
* else 'noindex, nofollow' for a page with requiresAuth: true (a signed-in
* or auth page, D-23), else null (the CMS decides).
*/
export function pageMetaRobots(meta: Record<string, unknown> | undefined | null): string | null {
if (!meta || typeof meta !== 'object') return null
const seo = meta.seo
if (seo && typeof seo === 'object') {
const robots = (seo as { robots?: unknown }).robots
if (typeof robots === 'string' && robots.trim() !== '') return robots.trim()
}
if (meta.requiresAuth === true) return 'noindex, nofollow'
return null
}

View File

@@ -73,6 +73,13 @@ export default defineNuxtModule<SeoModuleOptions>({
const ssr = nuxt.options.ssr !== false
const inlineRouteRules = nuxt.options.experimental?.inlineRouteRules === true
// requiresAuth and seo are read from definePageMeta at build time, so
// the route report leaves signed-in and noindex pages out (D-23).
const extract = new Set(nuxt.options.experimental.extraPageMetaExtractionKeys ?? [])
extract.add('requiresAuth')
extract.add('seo')
nuxt.options.experimental.extraPageMetaExtractionKeys = [...extract]
// Build guard (D-70). Nitro's config hook runs once every layer and
// module has merged its rules into it; there the declared noindex
// routes get their X-Robots-Tag rule. The pages are resolved after