scribe-cms 0.0.13 → 0.0.14

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.
package/dist/index.js CHANGED
@@ -244,39 +244,7 @@ function resolveConfig(input, baseDir) {
244
244
  if (localeRouting.strategy === "search-param" && !localeRouting.param) {
245
245
  throw new Error('scribe config: localeRouting search-param requires a "param" name');
246
246
  }
247
- const localeFallbacks = {};
248
- for (const [locale, chain] of Object.entries(raw.localeFallbacks ?? {})) {
249
- if (!raw.locales.includes(locale)) {
250
- throw new Error(
251
- `scribe config: localeFallbacks key "${locale}" is not in locales [${raw.locales.join(", ")}]`
252
- );
253
- }
254
- const seen = /* @__PURE__ */ new Set();
255
- for (const fallback of chain) {
256
- if (!raw.locales.includes(fallback)) {
257
- throw new Error(
258
- `scribe config: localeFallbacks["${locale}"] entry "${fallback}" is not in locales [${raw.locales.join(", ")}]`
259
- );
260
- }
261
- if (fallback === locale) {
262
- throw new Error(
263
- `scribe config: localeFallbacks["${locale}"] must not contain its own key "${locale}"`
264
- );
265
- }
266
- if (fallback === defaultLocale) {
267
- throw new Error(
268
- `scribe config: localeFallbacks["${locale}"] must not contain the defaultLocale "${defaultLocale}" \u2014 it is always the final fallback; remove it`
269
- );
270
- }
271
- if (seen.has(fallback)) {
272
- throw new Error(
273
- `scribe config: localeFallbacks["${locale}"] contains duplicate entry "${fallback}"`
274
- );
275
- }
276
- seen.add(fallback);
277
- }
278
- localeFallbacks[locale] = [...chain];
279
- }
247
+ const localeFallbacks = raw.localeFallbacks === false ? {} : deriveLocaleFallbacks(raw.locales, defaultLocale);
280
248
  const projectRoot = path3.resolve(baseDir ?? process.cwd(), raw.rootDir);
281
249
  const contentRoot = path3.resolve(projectRoot, raw.contentDir ?? "content");
282
250
  const storePath = path3.resolve(projectRoot, raw.store ?? ".scribe/store.sqlite");
@@ -316,6 +284,25 @@ function resolveConfig(input, baseDir) {
316
284
  });
317
285
  return config;
318
286
  }
287
+ function deriveLocaleFallbacks(locales, defaultLocale) {
288
+ const byLowercase = new Map(locales.map((l) => [l.toLowerCase(), l]));
289
+ const fallbacks = {};
290
+ for (const locale of locales) {
291
+ const subtags = locale.split("-");
292
+ if (subtags.length < 2) continue;
293
+ const chain = [];
294
+ for (let end = subtags.length - 1; end >= 1; end--) {
295
+ const prefix = byLowercase.get(subtags.slice(0, end).join("-").toLowerCase());
296
+ if (prefix && prefix !== locale && prefix !== defaultLocale) {
297
+ chain.push(prefix);
298
+ }
299
+ }
300
+ if (chain.length > 0) {
301
+ fallbacks[locale] = chain;
302
+ }
303
+ }
304
+ return fallbacks;
305
+ }
319
306
 
320
307
  // src/core/introspect-schema.ts
321
308
  function getArrayElement(schema) {