Files
vue-seo-layer/lib/routes.ts
Jakub Zych 9cc2cda924 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
2026-11-04 11:49:14 +01:00

26 lines
1.2 KiB
TypeScript

// 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
}