feat: the route report sends the noindex static paths (tracer)

- noindexStaticRoutes: requiresAuth, noindex/none seo.robots and static
  pages under seo.noindexRoutes, i18n copies included, never patterns or
  the layer's HTML sitemap pages (G1, gap-2 contract)
- #seo-routes exports noindexPaths; routeReportBody(paths, noindex) answers
  {routes, noindex} with the same limits and keeps the JSON body within the
  older plugin's 4,113,024 bytes, dropping noindex entries first
- smoke grammar noindex= and lacksnoindex=; README carries the contract
This commit is contained in:
Jakub Zych
2026-11-04 22:40:38 +01:00
parent b3a0078fb0
commit 7a26692001
9 changed files with 206 additions and 43 deletions

View File

@@ -83,6 +83,28 @@ export function staticRoutes(pages: readonly RoutePage[], noindexRoutes: readonl
return [...out].sort()
}
/**
* The paths without parameters the build serves noindex, sorted (G1, the
* route report's `noindex` list): pages whose meta keeps them out of the
* index (requiresAuth, a noindex or none seo.robots) and static pages under
* seo.noindexRoutes. Client-only pages count (they are noindex by the
* guard's rule) and so do the @nuxtjs/i18n copies in other locales, which
* are listed as their own locale-prefixed paths ('/pl/konto'). Never a
* pattern, never a path with a parameter or a catch-all, never one of the
* layer's HTML sitemap pages, and never a path staticRoutes lists.
*/
export function noindexStaticRoutes(pages: readonly RoutePage[], noindexRoutes: readonly string[]): string[] {
const out = new Set<string>()
for (const page of flattenPages(pages) as Array<RoutePage & { fullPath: string }>) {
if (Array.isArray(page.children) && page.children.some((c) => c.path === '')) continue
const path = page.fullPath
if (path.includes(':') || path.includes('*')) continue
if (isLayerPage(page.name)) continue
if (robotsNoindex(pageMetaRobots(page.meta)) || isNoindex(path, noindexRoutes)) out.add(path)
}
return [...out].sort()
}
/** Every page's route pattern ('/posts/:slug', '/**' for a catch-all), sorted. */
export function routePatterns(pages: readonly RoutePage[]): RoutePattern[] {
const seen = new Map<string, RoutePattern>()
@@ -94,11 +116,12 @@ export function routePatterns(pages: readonly RoutePage[]): RoutePattern[] {
}
/** The body of the server template #seo-routes. */
export function routesTemplate(staticPaths: readonly string[], patterns: readonly RoutePattern[]): string {
export function routesTemplate(staticPaths: readonly string[], patterns: readonly RoutePattern[], noindexPaths: readonly string[] = []): string {
return [
'// Generated by vue-seo-layer (lib/routes.ts) from the resolved pages.',
`export const staticRoutes = ${JSON.stringify(staticPaths)}`,
`export const routePatterns = ${JSON.stringify(patterns)}`,
`export const noindexPaths = ${JSON.stringify(noindexPaths)}`,
'',
].join('\n')
}

View File

@@ -12,7 +12,7 @@ import { fileURLToPath } from 'node:url'
import { addServerTemplate, defineNuxtModule, extendPages, useLogger } from 'nuxt/kit'
import { findOffenders, guardMessage, noindexRule, type GuardPage } from './guard.ts'
import { htmlSitemapOption, paginationOption, type SeoHtmlSitemapOption, type SeoPaginationOption } from './options.ts'
import { localeCopySuffixes, routePatterns, routesTemplate, staticRoutes, type RoutePage } from './routes.ts'
import { localeCopySuffixes, noindexStaticRoutes, routePatterns, routesTemplate, staticRoutes, type RoutePage } from './routes.ts'
export interface SeoModuleOptions {
/**
@@ -175,15 +175,19 @@ export default defineNuxtModule<SeoModuleOptions>({
})
}
// The route artefact (#seo-routes) for the route report and the drift
// check: written from the resolved pages when Nitro bundles the
// The route artefact (#seo-routes) for the route report (indexable and
// noindex static paths) and the drift check: written from the resolved pages when Nitro bundles the
// server, so no network call happens at build time.
addServerTemplate({
filename: '#seo-routes',
getContents: () => {
const resolved = (pages ?? []) as RoutePage[]
const i18n = (nuxt.options as { i18n?: unknown }).i18n
return routesTemplate(staticRoutes(resolved, noindexRoutes, localeCopySuffixes(i18n)), routePatterns(resolved))
return routesTemplate(
staticRoutes(resolved, noindexRoutes, localeCopySuffixes(i18n)),
routePatterns(resolved),
noindexStaticRoutes(resolved, noindexRoutes),
)
},
})
nuxt.hook('nitro:build:before', (nitro) => {