fix: leave the i18n copies of a page in other locales out of the route report

With prefix_except_default (or prefix_and_default) @nuxtjs/i18n adds a copy
of every page per other locale (/pl/contact next to /contact). The route
report sent them as pages of their own, so the CMS registry got a second,
untranslated page for each. They are the page's translations: the report
now skips routes named with another locale's suffix (contact___pl).
This commit is contained in:
Jakub Zych
2026-11-04 20:13:05 +01:00
parent 75cc100336
commit b3a0078fb0
4 changed files with 50 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { htmlSitemapOption, paginationOption } from '../lib/options.ts'
import { pageMetaRobots, robotsNoindex, routePatterns, routesTemplate, staticRoutes } from '../lib/routes.ts'
import { localeCopySuffixes, pageMetaRobots, robotsNoindex, routePatterns, routesTemplate, staticRoutes } from '../lib/routes.ts'
import { DRIFT_PREFIX, driftWarnings, routeServes } from '../server/lib/drift.ts'
import { ROUTE_REPORT_MAX_ROUTES, routeReportBody, routeReportOutcome } from '../server/lib/routeReport.ts'
@@ -124,3 +124,25 @@ test('routeServes normalises CMS patterns: {param} and :param alike, the query p
assert.equal(routeServes(route, '/blog/{category}/{slug}'), false)
assert.equal(routeServes({ pattern: '/docs/**', catchAll: true }, '/docs/{a}/{b}'), true)
})
test('localeCopySuffixes: the other locales of a prefixed strategy, none without one', () => {
const locales = [{ code: 'en' }, { code: 'pl' }, 'de']
assert.deepEqual(localeCopySuffixes({ strategy: 'prefix_except_default', defaultLocale: 'en', locales }), ['___pl', '___de'])
assert.deepEqual(localeCopySuffixes({ defaultLocale: 'en', locales, routesNameSeparator: '__' }), ['__pl', '__de'])
assert.deepEqual(localeCopySuffixes({ strategy: 'prefix_and_default', defaultLocale: 'pl', locales }), ['___en', '___de'])
assert.deepEqual(localeCopySuffixes({ strategy: 'no_prefix', defaultLocale: 'en', locales }), [])
assert.deepEqual(localeCopySuffixes({ strategy: 'prefix_except_default', locales }), [])
assert.deepEqual(localeCopySuffixes(undefined), [])
})
test('staticRoutes leaves out the i18n copies of a page in the other locales', () => {
const localized = [
{ path: '/', name: 'index___en' },
{ path: '/pl', name: 'index___pl' },
{ path: '/contact', name: 'contact___en' },
{ path: '/pl/contact', name: 'contact___pl' },
{ path: '/pl/konto', name: 'konto___pl', meta: { requiresAuth: true } },
]
assert.deepEqual(staticRoutes(localized, [], ['___pl']), ['/', '/contact'])
assert.deepEqual(staticRoutes(localized, []), ['/', '/contact', '/pl', '/pl/contact'])
})