nuxtseo-shared 5.3.11 → 5.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,15 +7,24 @@
7
7
  * Feed it the config `toRuntimeI18nConfig()` produces.
8
8
  */
9
9
  /**
10
- * Custom route paths keyed by route name, then locale code — i18n's `pages`
11
- * option (`globalLocaleRoutes` for nuxt-i18n-micro). `false` means the page is
12
- * disabled for that locale.
10
+ * Resolved route paths keyed by route name, then locale code. Per-locale
11
+ * `false` disables that locale. A tagged unlocalized entry represents i18n's
12
+ * whole-route `false` after build-time materialization.
13
13
  *
14
14
  * ```
15
- * { about: { en: '/about', fr: '/a-propos' } }
15
+ * { about: { en: '/about', fr: '/a-propos' }, admin: { _tag: 'unlocalized', path: '/admin' } }
16
16
  * ```
17
17
  */
18
- type LocalePages = Record<string, Record<string, string | false> | undefined>;
18
+ type LocalePagePaths = Record<string, string | false>;
19
+ interface UnlocalizedLocalePage {
20
+ /** Route excluded from i18n localization by a whole-route `pages` false. */
21
+ _tag: 'unlocalized';
22
+ /** Original resolved Nuxt route pattern. */
23
+ path: string;
24
+ /** The route has children, which i18n also leaves unlocalized. */
25
+ subtree?: true;
26
+ }
27
+ type LocalePages = Record<string, LocalePagePaths | UnlocalizedLocalePage | undefined>;
19
28
  interface RuntimeLocale {
20
29
  code: string;
21
30
  hreflang: string;
@@ -61,6 +70,11 @@ interface RuntimeRouteContext {
61
70
  /** Known current locale, required to translate no_prefix routes without a locale domain. */
62
71
  locale?: string;
63
72
  }
73
+ /**
74
+ * Resolve the canonical domain for a locale. Domainless locales are served on
75
+ * every domain, so their stable canonical is the default locale's domain.
76
+ */
77
+ declare function resolveCanonicalLocaleDomain(locale: RuntimeLocale | undefined, defaultLocale?: RuntimeLocale): string | undefined;
64
78
  /**
65
79
  * Resolve which locale a route belongs to and the locale-stripped base path.
66
80
  */
@@ -80,5 +94,5 @@ declare function localePath(basePath: string, locale: string, i18n: RuntimeI18nC
80
94
  declare function resolveLocaleAlternates(route: string, i18n: RuntimeI18nConfig, context?: RuntimeRouteContext): LocaleAlternateResolution;
81
95
  declare function computeLocaleAlternates(route: string, i18n: RuntimeI18nConfig, context?: RuntimeRouteContext): LocaleAlternate[];
82
96
 
83
- export { computeLocaleAlternates, localePath, resolveLocaleAlternates, resolveLocaleFromRoute };
84
- export type { LocaleAlternate, LocaleAlternateResolution, LocalePages, RouteLocaleInfo, RuntimeI18nConfig, RuntimeLocale, RuntimeRouteContext };
97
+ export { computeLocaleAlternates, localePath, resolveCanonicalLocaleDomain, resolveLocaleAlternates, resolveLocaleFromRoute };
98
+ export type { LocaleAlternate, LocaleAlternateResolution, LocalePagePaths, LocalePages, RouteLocaleInfo, RuntimeI18nConfig, RuntimeLocale, RuntimeRouteContext, UnlocalizedLocalePage };
@@ -7,15 +7,24 @@
7
7
  * Feed it the config `toRuntimeI18nConfig()` produces.
8
8
  */
9
9
  /**
10
- * Custom route paths keyed by route name, then locale code — i18n's `pages`
11
- * option (`globalLocaleRoutes` for nuxt-i18n-micro). `false` means the page is
12
- * disabled for that locale.
10
+ * Resolved route paths keyed by route name, then locale code. Per-locale
11
+ * `false` disables that locale. A tagged unlocalized entry represents i18n's
12
+ * whole-route `false` after build-time materialization.
13
13
  *
14
14
  * ```
15
- * { about: { en: '/about', fr: '/a-propos' } }
15
+ * { about: { en: '/about', fr: '/a-propos' }, admin: { _tag: 'unlocalized', path: '/admin' } }
16
16
  * ```
17
17
  */
18
- type LocalePages = Record<string, Record<string, string | false> | undefined>;
18
+ type LocalePagePaths = Record<string, string | false>;
19
+ interface UnlocalizedLocalePage {
20
+ /** Route excluded from i18n localization by a whole-route `pages` false. */
21
+ _tag: 'unlocalized';
22
+ /** Original resolved Nuxt route pattern. */
23
+ path: string;
24
+ /** The route has children, which i18n also leaves unlocalized. */
25
+ subtree?: true;
26
+ }
27
+ type LocalePages = Record<string, LocalePagePaths | UnlocalizedLocalePage | undefined>;
19
28
  interface RuntimeLocale {
20
29
  code: string;
21
30
  hreflang: string;
@@ -61,6 +70,11 @@ interface RuntimeRouteContext {
61
70
  /** Known current locale, required to translate no_prefix routes without a locale domain. */
62
71
  locale?: string;
63
72
  }
73
+ /**
74
+ * Resolve the canonical domain for a locale. Domainless locales are served on
75
+ * every domain, so their stable canonical is the default locale's domain.
76
+ */
77
+ declare function resolveCanonicalLocaleDomain(locale: RuntimeLocale | undefined, defaultLocale?: RuntimeLocale): string | undefined;
64
78
  /**
65
79
  * Resolve which locale a route belongs to and the locale-stripped base path.
66
80
  */
@@ -80,5 +94,5 @@ declare function localePath(basePath: string, locale: string, i18n: RuntimeI18nC
80
94
  declare function resolveLocaleAlternates(route: string, i18n: RuntimeI18nConfig, context?: RuntimeRouteContext): LocaleAlternateResolution;
81
95
  declare function computeLocaleAlternates(route: string, i18n: RuntimeI18nConfig, context?: RuntimeRouteContext): LocaleAlternate[];
82
96
 
83
- export { computeLocaleAlternates, localePath, resolveLocaleAlternates, resolveLocaleFromRoute };
84
- export type { LocaleAlternate, LocaleAlternateResolution, LocalePages, RouteLocaleInfo, RuntimeI18nConfig, RuntimeLocale, RuntimeRouteContext };
97
+ export { computeLocaleAlternates, localePath, resolveCanonicalLocaleDomain, resolveLocaleAlternates, resolveLocaleFromRoute };
98
+ export type { LocaleAlternate, LocaleAlternateResolution, LocalePagePaths, LocalePages, RouteLocaleInfo, RuntimeI18nConfig, RuntimeLocale, RuntimeRouteContext, UnlocalizedLocalePage };
@@ -1,3 +1,14 @@
1
+ function isUnlocalizedLocalePage(page) {
2
+ return page._tag === "unlocalized" && typeof page.path === "string";
3
+ }
4
+ function matchesUnlocalizedLocalePage(page, path) {
5
+ if (matchPagePattern(page.path, path))
6
+ return true;
7
+ if (!page.subtree)
8
+ return false;
9
+ const subtreePattern = `${page.path === "/" ? "" : page.path.replace(/\/$/, "")}/[...__nuxtSeoSubtree]`;
10
+ return !!matchPagePattern(subtreePattern, path);
11
+ }
1
12
  function normalizeHost(value) {
2
13
  return value.trim().toLowerCase().replace(/^[a-z][a-z\d+.-]*:\/\//, "").split("/")[0];
3
14
  }
@@ -18,8 +29,11 @@ function resolveLocaleFromHost(host, i18n) {
18
29
  );
19
30
  return matches.length === 1 ? matches[0] : matches.find((locale) => locale.code === i18n.defaultLocale);
20
31
  }
21
- function resolveLocaleDomain(locale) {
22
- return locale.defaultForDomains?.[0] || locale.domain || locale.domains?.[0];
32
+ function firstLocaleDomain(locale) {
33
+ return locale?.defaultForDomains?.[0] || locale?.domain || locale?.domains?.[0];
34
+ }
35
+ function resolveCanonicalLocaleDomain(locale, defaultLocale) {
36
+ return firstLocaleDomain(locale) || firstLocaleDomain(defaultLocale);
23
37
  }
24
38
  function splitRouteSuffix(route) {
25
39
  const suffixIndex = route.search(/[?#]/);
@@ -37,7 +51,8 @@ function resolveLocaleFromRoute(route, i18n, context = {}) {
37
51
  const matched = first ? i18n.locales.find((l) => l.code === first) : void 0;
38
52
  if (matched) {
39
53
  const rest = segments.slice(1).join("/");
40
- return { locale: matched.code, basePath: `${rest ? `/${rest}` : "/"}${suffix}` };
54
+ const trailingSlash = rest && pathname.endsWith("/") ? "/" : "";
55
+ return { locale: matched.code, basePath: `${rest ? `/${rest}${trailingSlash}` : "/"}${suffix}` };
41
56
  }
42
57
  }
43
58
  const contextLocale = context.locale ? i18n.locales.find((locale) => locale.code === context.locale) : void 0;
@@ -64,7 +79,7 @@ function localePath(basePath, locale, i18n, context = {}) {
64
79
  function toSegments(path) {
65
80
  return path.split("/").filter(Boolean);
66
81
  }
67
- const PAGE_PARAM_PATTERN = /\[\[(\.\.\.)?([^[\]]+)\]\]|\[(\.\.\.)?([^[\]]+)\]|:(\w+)(?:\((\.\*)\))?([?*+]?)/g;
82
+ const PAGE_PARAM_PATTERN = /\[\[(\.\.\.)?([^[\]]+)\]\]|\[(\.\.\.)?([^[\]]+)\]|:(\w+)(?:\((\.\*)?\))?([?*+]?)/g;
68
83
  function parsePageSegment(segment) {
69
84
  const tokens = [];
70
85
  let offset = 0;
@@ -78,11 +93,12 @@ function parsePageSegment(segment) {
78
93
  tokens.push({ _tag: "param", param: { name: match[4], catchAll: !!match[3], optional: false } });
79
94
  } else {
80
95
  const modifier = match[7];
96
+ const routePattern = match[6];
81
97
  tokens.push({
82
98
  _tag: "param",
83
99
  param: {
84
100
  name: match[5],
85
- catchAll: !!match[6] || modifier === "*" || modifier === "+",
101
+ catchAll: !!routePattern?.includes(".*") || modifier === "*" || modifier === "+",
86
102
  optional: modifier === "?" || modifier === "*"
87
103
  }
88
104
  });
@@ -121,12 +137,23 @@ function compareSpecificity(a, b) {
121
137
  return a.length - b.length;
122
138
  }
123
139
  function matchSegmentTokens(tokens, path) {
140
+ const failedStates = /* @__PURE__ */ new Set();
124
141
  function visit(index, offset, params) {
125
- if (index === tokens.length)
126
- return offset === path.length ? params : null;
142
+ const state = index * (path.length + 1) + offset;
143
+ if (failedStates.has(state))
144
+ return null;
145
+ if (index === tokens.length) {
146
+ if (offset === path.length)
147
+ return params;
148
+ failedStates.add(state);
149
+ return null;
150
+ }
127
151
  const token = tokens[index];
128
152
  if (token._tag === "static") {
129
- return path.startsWith(token.value, offset) ? visit(index + 1, offset + token.value.length, params) : null;
153
+ const matched = path.startsWith(token.value, offset) ? visit(index + 1, offset + token.value.length, params) : null;
154
+ if (!matched)
155
+ failedStates.add(state);
156
+ return matched;
130
157
  }
131
158
  const minimumEnd = token.param.optional ? offset : offset + 1;
132
159
  for (let end = minimumEnd; end <= path.length; end++) {
@@ -136,6 +163,7 @@ function matchSegmentTokens(tokens, path) {
136
163
  if (matched)
137
164
  return matched;
138
165
  }
166
+ failedStates.add(state);
139
167
  return null;
140
168
  }
141
169
  return visit(0, 0, {});
@@ -143,9 +171,17 @@ function matchSegmentTokens(tokens, path) {
143
171
  function matchPagePattern(pattern, path) {
144
172
  const patternSegments = toSegments(pattern);
145
173
  const pathSegments = toSegments(path);
174
+ const failedStates = /* @__PURE__ */ new Set();
146
175
  function visit(patternIndex, pathIndex, params) {
147
- if (patternIndex === patternSegments.length)
148
- return pathIndex === pathSegments.length ? params : null;
176
+ const state = patternIndex * (pathSegments.length + 1) + pathIndex;
177
+ if (failedStates.has(state))
178
+ return null;
179
+ if (patternIndex === patternSegments.length) {
180
+ if (pathIndex === pathSegments.length)
181
+ return params;
182
+ failedStates.add(state);
183
+ return null;
184
+ }
149
185
  const tokens = parsePageSegment(patternSegments[patternIndex]);
150
186
  const param = wholeSegmentParam(tokens);
151
187
  if (param?.catchAll) {
@@ -153,22 +189,26 @@ function matchPagePattern(pattern, path) {
153
189
  for (let end = pathSegments.length; end >= minimumEnd; end--) {
154
190
  const value = pathSegments.slice(pathIndex, end).join("/");
155
191
  const nextParams = value ? { ...params, [param.name]: value } : params;
156
- const matched = visit(patternIndex + 1, end, nextParams);
157
- if (matched)
158
- return matched;
192
+ const matched2 = visit(patternIndex + 1, end, nextParams);
193
+ if (matched2)
194
+ return matched2;
159
195
  }
196
+ failedStates.add(state);
160
197
  return null;
161
198
  }
162
199
  const segment = pathSegments[pathIndex];
163
200
  if (segment !== void 0) {
164
201
  const segmentParams = matchSegmentTokens(tokens, segment);
165
202
  if (segmentParams) {
166
- const matched = visit(patternIndex + 1, pathIndex + 1, { ...params, ...segmentParams });
167
- if (matched)
168
- return matched;
203
+ const matched2 = visit(patternIndex + 1, pathIndex + 1, { ...params, ...segmentParams });
204
+ if (matched2)
205
+ return matched2;
169
206
  }
170
207
  }
171
- return param?.optional ? visit(patternIndex + 1, pathIndex, params) : null;
208
+ const matched = param?.optional ? visit(patternIndex + 1, pathIndex, params) : null;
209
+ if (!matched)
210
+ failedStates.add(state);
211
+ return matched;
172
212
  }
173
213
  return visit(0, 0, {});
174
214
  }
@@ -193,11 +233,14 @@ function fillPagePattern(pattern, params) {
193
233
  if (value)
194
234
  filled.push(value);
195
235
  }
196
- return filled.length ? `/${filled.join("/")}` : "/";
236
+ if (!filled.length)
237
+ return "/";
238
+ return `/${filled.join("/")}${pattern.endsWith("/") ? "/" : ""}`;
197
239
  }
198
240
  function alternatesForEntry(localePaths, params, i18n, context) {
199
241
  const untranslated = localePaths[i18n.defaultLocale];
200
242
  const alternates = [];
243
+ const defaultLocale = i18n.locales.find((locale) => locale.code === i18n.defaultLocale);
201
244
  for (const l of i18n.locales) {
202
245
  const pattern = localePaths[l.code] ?? untranslated;
203
246
  if (localePaths[l.code] === false)
@@ -207,7 +250,7 @@ function alternatesForEntry(localePaths, params, i18n, context) {
207
250
  const path = fillPagePattern(pattern, params);
208
251
  if (path === null)
209
252
  continue;
210
- const domain = resolveLocaleDomain(l);
253
+ const domain = resolveCanonicalLocaleDomain(l, defaultLocale);
211
254
  alternates.push({
212
255
  code: l.code,
213
256
  hreflang: l.hreflang || l.code,
@@ -217,23 +260,46 @@ function alternatesForEntry(localePaths, params, i18n, context) {
217
260
  }
218
261
  return alternates.length ? alternates : null;
219
262
  }
220
- function alternatesFromPages(basePath, locale, i18n, context) {
263
+ function alternatesFromPages(basePath, routePath, locale, i18n, context) {
221
264
  const pages = i18n.pages;
222
265
  const hasDomainLocales = i18n.differentDomains || i18n.multiDomainLocales;
223
266
  const hasContextLocale = !!context.locale && i18n.locales.some((locale2) => locale2.code === context.locale);
224
- if (!pages || i18n.strategy === "no_prefix" && !hasDomainLocales && !hasContextLocale)
267
+ if (!pages)
225
268
  return null;
269
+ const allowLocalized = i18n.strategy !== "no_prefix" || hasDomainLocales || hasContextLocale;
226
270
  const matches = [];
227
- for (const localePaths of Object.values(pages)) {
228
- const pattern = localePaths?.[locale];
271
+ for (const page of Object.values(pages)) {
272
+ if (!page)
273
+ continue;
274
+ if (isUnlocalizedLocalePage(page)) {
275
+ if (matchesUnlocalizedLocalePage(page, routePath))
276
+ matches.push({ _tag: "unlocalized", ranks: segmentRanks(page.path) });
277
+ continue;
278
+ }
279
+ if (!allowLocalized)
280
+ continue;
281
+ const pattern = page[locale];
229
282
  if (!pattern)
230
283
  continue;
231
284
  const params = matchPagePattern(pattern, basePath);
232
285
  if (params)
233
- matches.push({ ranks: segmentRanks(pattern), localePaths, params });
286
+ matches.push({ _tag: "localized", ranks: segmentRanks(pattern), localePaths: page, params });
234
287
  }
235
288
  matches.sort((a, b) => compareSpecificity(a.ranks, b.ranks));
236
289
  for (const match of matches) {
290
+ if (match._tag === "unlocalized") {
291
+ const defaultLocale = i18n.locales.find((locale2) => locale2.code === i18n.defaultLocale);
292
+ if (defaultLocale) {
293
+ const domain = resolveCanonicalLocaleDomain(defaultLocale);
294
+ return [{
295
+ code: defaultLocale.code,
296
+ hreflang: defaultLocale.hreflang || defaultLocale.code,
297
+ path: routePath,
298
+ ...domain ? { domain } : {}
299
+ }];
300
+ }
301
+ continue;
302
+ }
237
303
  const alternates = alternatesForEntry(match.localePaths, match.params, i18n, context);
238
304
  if (alternates)
239
305
  return alternates;
@@ -243,17 +309,19 @@ function alternatesFromPages(basePath, locale, i18n, context) {
243
309
  function resolveLocaleAlternates(route, i18n, context = {}) {
244
310
  const { locale, basePath } = resolveLocaleFromRoute(route, i18n, context);
245
311
  const { pathname, suffix } = splitRouteSuffix(basePath);
246
- const translated = alternatesFromPages(pathname, locale, i18n, context);
312
+ const { pathname: routePathname } = splitRouteSuffix(route);
313
+ const translated = alternatesFromPages(pathname, routePathname, locale, i18n, context);
247
314
  if (translated) {
248
315
  return {
249
316
  _tag: "pages",
250
317
  alternates: translated.map((alternate) => ({ ...alternate, path: `${alternate.path}${suffix}` }))
251
318
  };
252
319
  }
320
+ const defaultLocale = i18n.locales.find((locale2) => locale2.code === i18n.defaultLocale);
253
321
  return {
254
322
  _tag: "strategy",
255
323
  alternates: i18n.locales.map((l) => {
256
- const domain = resolveLocaleDomain(l);
324
+ const domain = resolveCanonicalLocaleDomain(l, defaultLocale);
257
325
  return {
258
326
  code: l.code,
259
327
  hreflang: l.hreflang || l.code,
@@ -267,4 +335,4 @@ function computeLocaleAlternates(route, i18n, context = {}) {
267
335
  return resolveLocaleAlternates(route, i18n, context).alternates;
268
336
  }
269
337
 
270
- export { computeLocaleAlternates, localePath, resolveLocaleAlternates, resolveLocaleFromRoute };
338
+ export { computeLocaleAlternates, localePath, resolveCanonicalLocaleDomain, resolveLocaleAlternates, resolveLocaleFromRoute };
package/dist/i18n.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LocaleObject, NuxtI18nOptions } from '@nuxtjs/i18n';
2
- import { RuntimeI18nConfig } from './i18n-runtime.mjs';
3
- export { LocaleAlternate, LocaleAlternateResolution, LocalePages, RouteLocaleInfo, RuntimeLocale, RuntimeRouteContext } from './i18n-runtime.mjs';
2
+ import { UnlocalizedLocalePage, RuntimeI18nConfig } from './i18n-runtime.mjs';
3
+ export { LocaleAlternate, LocaleAlternateResolution, LocalePagePaths, LocalePages, RouteLocaleInfo, RuntimeLocale, RuntimeRouteContext } from './i18n-runtime.mjs';
4
4
 
5
5
  declare const I18N_MODULES: readonly ["@nuxtjs/i18n", "nuxt-i18n-micro"];
6
6
  type I18nModuleName = typeof I18N_MODULES[number];
@@ -15,8 +15,11 @@ interface AutoI18nConfig {
15
15
  strategy: Strategies;
16
16
  differentDomains?: boolean;
17
17
  multiDomainLocales?: boolean;
18
- pages?: Record<string, Record<string, string | false>>;
18
+ routesNameSeparator?: string;
19
+ defaultLocaleRouteNameSuffix?: string;
20
+ pages?: Record<string, Record<string, string | false> | UnlocalizedLocalePage | false>;
19
21
  }
22
+ type I18nPages = NonNullable<AutoI18nConfig['pages']>;
20
23
  interface StrategyProps {
21
24
  localeCode: string;
22
25
  pageLocales: string;
@@ -50,7 +53,22 @@ declare function isCompactLocaleRoute(path: string): boolean;
50
53
  */
51
54
  declare function expandCompactLocaleRoute(path: string, knownLocales?: string[]): ExpandedLocaleRoute[] | null;
52
55
  declare function normalizeLocales(nuxtI18nConfig: NuxtI18nOptions): AutoI18nConfig['locales'];
53
- declare function mapPathForI18nPages(path: string, autoI18n: AutoI18nConfig): string[] | false;
56
+ interface ResolvedI18nRoute {
57
+ name?: string;
58
+ path: string;
59
+ children?: ResolvedI18nRoute[];
60
+ }
61
+ /** Normalize an i18n `pages` key to the corresponding resolved Nuxt route name. Build-time only. */
62
+ declare function normalizeI18nPageKey(key: string): string;
63
+ /**
64
+ * Complete partial i18n `pages` entries from Nuxt's resolved route table.
65
+ *
66
+ * Route names are identifiers, not URL paths. The resolved route path is the
67
+ * only safe fallback for nested, dynamic, grouped, or custom Nuxt routes.
68
+ * Whole-route `false` becomes a tagged entry carrying that resolved path.
69
+ */
70
+ declare function materializeI18nPages(autoI18n: AutoI18nConfig, routes: readonly ResolvedI18nRoute[]): I18nPages | undefined;
71
+ declare function mapPathForI18nPages(path: string, autoI18n: AutoI18nConfig, routes?: readonly ResolvedI18nRoute[]): string[] | false;
54
72
  interface I18nModuleResolution {
55
73
  module: I18nModuleName;
56
74
  isMicro: boolean;
@@ -67,10 +85,12 @@ declare function resolveI18nConfig(logger?: {
67
85
  /**
68
86
  * Strip a build-time i18n config down to what `./i18n-runtime` needs, dropping
69
87
  * the non-serializable `LocaleObject` extras so it can be handed to the runtime
70
- * through `runtimeConfig`.
88
+ * through `runtimeConfig`. Materialize partial and whole-route-false `pages`
89
+ * entries before calling this function; unresolved whole-route false entries
90
+ * are omitted instead of becoming fabricated runtime URLs.
71
91
  */
72
92
  declare function toRuntimeI18nConfig(auto: AutoI18nConfig): RuntimeI18nConfig;
73
93
  declare function mergeOnKey<T extends Record<string, any>>(arr: T[], key: keyof T): T[];
74
94
 
75
- export { RuntimeI18nConfig, expandCompactLocaleRoute, generatePathForI18nPages, isCompactLocaleRoute, mapPathForI18nPages, mergeOnKey, normalizeLocales, resolveI18nConfig, resolveI18nModule, splitPathForI18nLocales, toRuntimeI18nConfig };
76
- export type { AutoI18nConfig, ExpandedLocaleRoute, I18nModuleResolution, NormalisedLocale, Strategies, StrategyProps };
95
+ export { RuntimeI18nConfig, UnlocalizedLocalePage, expandCompactLocaleRoute, generatePathForI18nPages, isCompactLocaleRoute, mapPathForI18nPages, materializeI18nPages, mergeOnKey, normalizeI18nPageKey, normalizeLocales, resolveI18nConfig, resolveI18nModule, splitPathForI18nLocales, toRuntimeI18nConfig };
96
+ export type { AutoI18nConfig, ExpandedLocaleRoute, I18nModuleResolution, NormalisedLocale, ResolvedI18nRoute, Strategies, StrategyProps };
package/dist/i18n.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LocaleObject, NuxtI18nOptions } from '@nuxtjs/i18n';
2
- import { RuntimeI18nConfig } from './i18n-runtime.js';
3
- export { LocaleAlternate, LocaleAlternateResolution, LocalePages, RouteLocaleInfo, RuntimeLocale, RuntimeRouteContext } from './i18n-runtime.js';
2
+ import { UnlocalizedLocalePage, RuntimeI18nConfig } from './i18n-runtime.js';
3
+ export { LocaleAlternate, LocaleAlternateResolution, LocalePagePaths, LocalePages, RouteLocaleInfo, RuntimeLocale, RuntimeRouteContext } from './i18n-runtime.js';
4
4
 
5
5
  declare const I18N_MODULES: readonly ["@nuxtjs/i18n", "nuxt-i18n-micro"];
6
6
  type I18nModuleName = typeof I18N_MODULES[number];
@@ -15,8 +15,11 @@ interface AutoI18nConfig {
15
15
  strategy: Strategies;
16
16
  differentDomains?: boolean;
17
17
  multiDomainLocales?: boolean;
18
- pages?: Record<string, Record<string, string | false>>;
18
+ routesNameSeparator?: string;
19
+ defaultLocaleRouteNameSuffix?: string;
20
+ pages?: Record<string, Record<string, string | false> | UnlocalizedLocalePage | false>;
19
21
  }
22
+ type I18nPages = NonNullable<AutoI18nConfig['pages']>;
20
23
  interface StrategyProps {
21
24
  localeCode: string;
22
25
  pageLocales: string;
@@ -50,7 +53,22 @@ declare function isCompactLocaleRoute(path: string): boolean;
50
53
  */
51
54
  declare function expandCompactLocaleRoute(path: string, knownLocales?: string[]): ExpandedLocaleRoute[] | null;
52
55
  declare function normalizeLocales(nuxtI18nConfig: NuxtI18nOptions): AutoI18nConfig['locales'];
53
- declare function mapPathForI18nPages(path: string, autoI18n: AutoI18nConfig): string[] | false;
56
+ interface ResolvedI18nRoute {
57
+ name?: string;
58
+ path: string;
59
+ children?: ResolvedI18nRoute[];
60
+ }
61
+ /** Normalize an i18n `pages` key to the corresponding resolved Nuxt route name. Build-time only. */
62
+ declare function normalizeI18nPageKey(key: string): string;
63
+ /**
64
+ * Complete partial i18n `pages` entries from Nuxt's resolved route table.
65
+ *
66
+ * Route names are identifiers, not URL paths. The resolved route path is the
67
+ * only safe fallback for nested, dynamic, grouped, or custom Nuxt routes.
68
+ * Whole-route `false` becomes a tagged entry carrying that resolved path.
69
+ */
70
+ declare function materializeI18nPages(autoI18n: AutoI18nConfig, routes: readonly ResolvedI18nRoute[]): I18nPages | undefined;
71
+ declare function mapPathForI18nPages(path: string, autoI18n: AutoI18nConfig, routes?: readonly ResolvedI18nRoute[]): string[] | false;
54
72
  interface I18nModuleResolution {
55
73
  module: I18nModuleName;
56
74
  isMicro: boolean;
@@ -67,10 +85,12 @@ declare function resolveI18nConfig(logger?: {
67
85
  /**
68
86
  * Strip a build-time i18n config down to what `./i18n-runtime` needs, dropping
69
87
  * the non-serializable `LocaleObject` extras so it can be handed to the runtime
70
- * through `runtimeConfig`.
88
+ * through `runtimeConfig`. Materialize partial and whole-route-false `pages`
89
+ * entries before calling this function; unresolved whole-route false entries
90
+ * are omitted instead of becoming fabricated runtime URLs.
71
91
  */
72
92
  declare function toRuntimeI18nConfig(auto: AutoI18nConfig): RuntimeI18nConfig;
73
93
  declare function mergeOnKey<T extends Record<string, any>>(arr: T[], key: keyof T): T[];
74
94
 
75
- export { RuntimeI18nConfig, expandCompactLocaleRoute, generatePathForI18nPages, isCompactLocaleRoute, mapPathForI18nPages, mergeOnKey, normalizeLocales, resolveI18nConfig, resolveI18nModule, splitPathForI18nLocales, toRuntimeI18nConfig };
76
- export type { AutoI18nConfig, ExpandedLocaleRoute, I18nModuleResolution, NormalisedLocale, Strategies, StrategyProps };
95
+ export { RuntimeI18nConfig, UnlocalizedLocalePage, expandCompactLocaleRoute, generatePathForI18nPages, isCompactLocaleRoute, mapPathForI18nPages, materializeI18nPages, mergeOnKey, normalizeI18nPageKey, normalizeLocales, resolveI18nConfig, resolveI18nModule, splitPathForI18nLocales, toRuntimeI18nConfig };
96
+ export type { AutoI18nConfig, ExpandedLocaleRoute, I18nModuleResolution, NormalisedLocale, ResolvedI18nRoute, Strategies, StrategyProps };
package/dist/i18n.mjs CHANGED
@@ -8,6 +8,9 @@ import 'pkg-types';
8
8
  import 'std-env';
9
9
 
10
10
  const I18N_MODULES = ["@nuxtjs/i18n", "nuxt-i18n-micro"];
11
+ function isUnlocalizedLocalePage(page) {
12
+ return page._tag === "unlocalized" && typeof page.path === "string";
13
+ }
11
14
  function generatePathForI18nPages(ctx) {
12
15
  const { localeCode, pageLocales, nuxtI18nConfig, forcedStrategy, normalisedLocales } = ctx;
13
16
  const locale = normalisedLocales.find((l) => l.code === localeCode);
@@ -78,28 +81,110 @@ function normalizeLocales(nuxtI18nConfig) {
78
81
  return { ...locale, _hreflang, _sitemap };
79
82
  });
80
83
  }
81
- function mapPathForI18nPages(path, autoI18n) {
84
+ function joinRoutePath(parentPath, path) {
85
+ if (path.startsWith("/"))
86
+ return path;
87
+ if (!path)
88
+ return parentPath || "/";
89
+ return `${parentPath === "/" ? "" : parentPath.replace(/\/$/, "")}/${path}`;
90
+ }
91
+ function resolveLocalizedRouteName(name, autoI18n) {
92
+ if (!name)
93
+ return { name, isDefaultTree: false };
94
+ const separator = autoI18n.routesNameSeparator || "___";
95
+ const defaultSuffix = autoI18n.defaultLocaleRouteNameSuffix || "default";
96
+ const segments = name.split(separator);
97
+ const isDefaultTree = segments.at(-1) === defaultSuffix && autoI18n.locales.some((locale2) => locale2.code === segments.at(-2));
98
+ if (isDefaultTree)
99
+ segments.pop();
100
+ const locale = autoI18n.locales.find((locale2) => locale2.code === segments.at(-1))?.code;
101
+ if (locale)
102
+ segments.pop();
103
+ return {
104
+ name: segments.join(separator),
105
+ ...locale ? { locale } : {},
106
+ isDefaultTree
107
+ };
108
+ }
109
+ function flattenResolvedI18nRoutes(routes, autoI18n, parentPath = "") {
110
+ return routes.flatMap((route) => {
111
+ const path = joinRoutePath(parentPath, route.path);
112
+ return [
113
+ { ...resolveLocalizedRouteName(route.name, autoI18n), path, hasChildren: !!route.children?.length },
114
+ ...flattenResolvedI18nRoutes(route.children || [], autoI18n, path)
115
+ ];
116
+ });
117
+ }
118
+ function normalizeI18nPageKey(key) {
119
+ return key.replace(/^\//, "").replace(/\/index$/, "").replace(/\[{1,2}(?:\.\.\.)?([^\]]+)\]{1,2}/g, "$1").split("/").filter((segment) => !/^\([^)]+\)$/.test(segment)).join("-");
120
+ }
121
+ function routeBasePath(route, autoI18n) {
122
+ if (!route.locale || autoI18n.strategy === "no_prefix")
123
+ return route.path;
124
+ return resolveLocaleFromRoute(route.path, toRuntimeI18nConfig(autoI18n), { locale: route.locale }).basePath;
125
+ }
126
+ function materializeI18nPages(autoI18n, routes) {
127
+ const pages = autoI18n.pages;
128
+ if (!pages)
129
+ return void 0;
130
+ const resolvedRoutes = flattenResolvedI18nRoutes(routes, autoI18n);
131
+ return Object.fromEntries(Object.entries(pages).map(([pageName, pageLocales]) => {
132
+ const normalizedPageName = normalizeI18nPageKey(pageName);
133
+ const namedRoutes = resolvedRoutes.filter((route) => route.name === pageName || route.name === normalizedPageName);
134
+ if (pageLocales === false) {
135
+ const route = namedRoutes.find((route2) => route2.locale === autoI18n.defaultLocale) || namedRoutes.find((route2) => !route2.locale) || namedRoutes[0];
136
+ return [pageName, route ? {
137
+ _tag: "unlocalized",
138
+ path: routeBasePath(route, autoI18n),
139
+ ...route.hasChildren ? { subtree: true } : {}
140
+ } : false];
141
+ }
142
+ if (isUnlocalizedLocalePage(pageLocales))
143
+ return [pageName, pageLocales];
144
+ const explicitlyMatchedRoute = resolvedRoutes.find((route) => Object.values(pageLocales).some(
145
+ (configuredPath) => typeof configuredPath === "string" && routeBasePath(route, autoI18n) === configuredPath
146
+ ));
147
+ const routeGroup = namedRoutes.length ? namedRoutes : explicitlyMatchedRoute?.name ? resolvedRoutes.filter((route) => route.name === explicitlyMatchedRoute.name) : [];
148
+ const defaultRoute = routeGroup.find((route) => route.locale === autoI18n.defaultLocale && route.isDefaultTree) || routeGroup.find((route) => route.locale === autoI18n.defaultLocale) || routeGroup.find((route) => !route.locale) || routeGroup.find((route) => route.locale && pageLocales[route.locale] === void 0);
149
+ const originalPath = defaultRoute ? routeBasePath(defaultRoute, autoI18n) : void 0;
150
+ const defaultPath = pageLocales[autoI18n.defaultLocale];
151
+ const fallbackPath = typeof defaultPath === "string" ? defaultPath : originalPath;
152
+ return [pageName, Object.fromEntries(autoI18n.locales.flatMap((locale) => {
153
+ const configuredPath = pageLocales[locale.code];
154
+ if (configuredPath !== void 0)
155
+ return [[locale.code, configuredPath]];
156
+ return fallbackPath === void 0 ? [] : [[locale.code, fallbackPath]];
157
+ }))];
158
+ }));
159
+ }
160
+ function mapPathForI18nPages(path, autoI18n, routes = []) {
82
161
  const pages = autoI18n.pages;
83
162
  if (!pages || !Object.keys(pages).length)
84
163
  return false;
85
- const materializedPages = Object.fromEntries(
86
- Object.entries(pages).map(([pageName, pageLocales]) => [
87
- pageName,
88
- Object.fromEntries(autoI18n.locales.map((locale) => {
89
- const configuredPath = pageLocales[locale.code];
90
- return [locale.code, configuredPath === void 0 ? `/${pageName}` : configuredPath];
91
- }))
92
- ])
93
- );
164
+ const materializedPages = routes.length ? materializeI18nPages(autoI18n, routes) : pages;
165
+ const resolvedRoutes = flattenResolvedI18nRoutes(routes, autoI18n);
166
+ const pagesForMapping = Object.fromEntries(Object.entries(materializedPages || {}).map(([pageName, pageLocales]) => {
167
+ if (pageLocales !== false)
168
+ return [pageName, pageLocales];
169
+ const normalizedPageName = normalizeI18nPageKey(pageName);
170
+ const route = resolvedRoutes.find((route2) => route2.name === pageName || route2.name === normalizedPageName);
171
+ if (!route)
172
+ return [pageName, false];
173
+ const originalPath = routeBasePath(route, autoI18n);
174
+ return [pageName, Object.fromEntries(autoI18n.locales.map((locale) => [
175
+ locale.code,
176
+ locale.code === autoI18n.defaultLocale ? originalPath : false
177
+ ]))];
178
+ }));
94
179
  const i18n = toRuntimeI18nConfig({
95
180
  ...autoI18n,
96
181
  strategy: autoI18n.strategy === "prefix_and_default" ? "prefix_except_default" : autoI18n.strategy,
97
- pages: materializedPages
182
+ pages: pagesForMapping
98
183
  });
99
184
  const resolved = resolveLocaleAlternates(path, i18n, autoI18n.strategy === "no_prefix" ? { locale: autoI18n.defaultLocale } : {});
100
185
  if (resolved._tag === "strategy")
101
186
  return false;
102
- return resolved.alternates.filter((alternate) => autoI18n.strategy !== "prefix_except_default" || alternate.code !== autoI18n.defaultLocale).map((alternate) => alternate.domain ? withHttps(withBase(alternate.path, alternate.domain)) : alternate.path);
187
+ return resolved.alternates.map((alternate) => alternate.domain ? withHttps(withBase(alternate.path, alternate.domain)) : alternate.path);
103
188
  }
104
189
  function resolveI18nModule() {
105
190
  const found = I18N_MODULES.find((m) => hasNuxtModule(m));
@@ -115,7 +200,7 @@ function resolveI18nPages(config, isMicro) {
115
200
  if (!routes)
116
201
  return void 0;
117
202
  return Object.fromEntries(
118
- Object.entries(routes).filter((entry) => typeof entry[1] === "object" && entry[1] !== null && !Array.isArray(entry[1]))
203
+ Object.entries(routes).filter((entry) => entry[1] === false || typeof entry[1] === "object" && entry[1] !== null && !Array.isArray(entry[1]))
119
204
  );
120
205
  }
121
206
  async function resolveI18nConfig(logger) {
@@ -138,6 +223,8 @@ async function resolveI18nConfig(logger) {
138
223
  return {
139
224
  differentDomains: nuxtI18nConfig.differentDomains,
140
225
  multiDomainLocales: nuxtI18nConfig.multiDomainLocales,
226
+ routesNameSeparator: nuxtI18nConfig.routesNameSeparator,
227
+ defaultLocaleRouteNameSuffix: nuxtI18nConfig.defaultLocaleRouteNameSuffix,
141
228
  defaultLocale: nuxtI18nConfig.defaultLocale,
142
229
  locales: normalisedLocales,
143
230
  strategy: nuxtI18nConfig.strategy,
@@ -145,6 +232,9 @@ async function resolveI18nConfig(logger) {
145
232
  };
146
233
  }
147
234
  function toRuntimeI18nConfig(auto) {
235
+ const pages = auto.pages && Object.fromEntries(
236
+ Object.entries(auto.pages).filter((entry) => entry[1] !== false)
237
+ );
148
238
  return {
149
239
  defaultLocale: auto.defaultLocale,
150
240
  strategy: auto.strategy,
@@ -153,7 +243,7 @@ function toRuntimeI18nConfig(auto) {
153
243
  // Translated route paths. Without these the runtime can only guess
154
244
  // alternates by adding/removing a locale prefix, which is wrong for every
155
245
  // page whose slug differs per locale.
156
- ...auto.pages && Object.keys(auto.pages).length ? { pages: auto.pages } : {},
246
+ ...pages && Object.keys(pages).length ? { pages } : {},
157
247
  locales: auto.locales.map((l) => {
158
248
  const raw = l;
159
249
  return {
@@ -182,4 +272,4 @@ function mergeOnKey(arr, key) {
182
272
  return [...map.values()];
183
273
  }
184
274
 
185
- export { expandCompactLocaleRoute, generatePathForI18nPages, isCompactLocaleRoute, mapPathForI18nPages, mergeOnKey, normalizeLocales, resolveI18nConfig, resolveI18nModule, splitPathForI18nLocales, toRuntimeI18nConfig };
275
+ export { expandCompactLocaleRoute, generatePathForI18nPages, isCompactLocaleRoute, mapPathForI18nPages, materializeI18nPages, mergeOnKey, normalizeI18nPageKey, normalizeLocales, resolveI18nConfig, resolveI18nModule, splitPathForI18nLocales, toRuntimeI18nConfig };
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "5.3.11",
7
+ "version": "5.3.12",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxtseo-shared",
3
3
  "type": "module",
4
- "version": "5.3.11",
4
+ "version": "5.3.12",
5
5
  "description": "Shared utilities for Nuxt SEO modules.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -107,7 +107,7 @@
107
107
  "h3": "^1.15.11",
108
108
  "nitropack": "^2.13.4",
109
109
  "nuxt": "^4.5.2",
110
- "nuxt-site-config": "^4.1.5",
110
+ "nuxt-site-config": "^4.2.0",
111
111
  "typescript": "6.0.3",
112
112
  "vitest": "^4.1.10",
113
113
  "vue": "^3.5.41",