@kirchdev/duxt 0.1.1-dev.16-c752db1 → 0.1.1-dev.18-c374611

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://www.schemastore.org/package.json",
3
3
  "name": "@kirchdev/duxt",
4
- "version": "0.1.1-dev.16-c752db1",
4
+ "version": "0.1.1-dev.18-c374611",
5
5
  "description": "Nuxt documentation layer on Content v3 — multi-repo, versioned docs from one compact source list.",
6
6
  "keywords": [
7
7
  "content-v3",
@@ -1,4 +1,6 @@
1
1
  import { queryCollection } from '@nuxt/content/nitro';
2
+ import { splitLocalePath } from '../../app/utils/locale-path';
3
+ import { sourcesForRoute } from '../../sources-resolve';
2
4
  import { duxtDefaults, mergeDuxtConfig } from '../../app/utils/duxt-config';
3
5
  import { stripFrontmatter } from '../utils/duxt-server-text';
4
6
 
@@ -21,31 +23,42 @@ export default defineEventHandler(async (event) => {
21
23
  const appConfig = useAppConfig() as { duxt?: Partial<DuxtConfig> };
22
24
  const duxt = mergeDuxtConfig(appConfig.duxt, duxtDefaults);
23
25
 
24
- const wanted = stripLocale(path.slice(0, -'.md'.length));
25
-
26
- // Longest prefix first, exactly as the app resolves a route: `/app/v2` beats
27
- // `/app` on `/app/v2/guide`.
28
- const sources = [...(duxt.resolvedSources ?? [])].sort(
29
- (a, b) => b.prefix.length - a.prefix.length
26
+ const i18n = (
27
+ useRuntimeConfig(event).public as {
28
+ i18n?: {
29
+ locales?: ({ code: string } | string)[];
30
+ defaultLocale?: string;
31
+ };
32
+ }
33
+ ).i18n;
34
+ const { path: wanted, locale } = splitLocalePath(
35
+ path.slice(0, -'.md'.length),
36
+ (i18n?.locales ?? []).map((entry) =>
37
+ typeof entry === 'string' ? entry : entry.code
38
+ )
39
+ );
40
+ // Nuxt i18n loads the consumer's merged Vue I18n config in its request hook.
41
+ // Browser-language detection's fallback is a different policy.
42
+ const fallbackLocale = event.context.nuxtI18n?.vueI18nOptions
43
+ ?.fallbackLocale as string | string[] | undefined;
44
+ const sources = sourcesForRoute(
45
+ wanted,
46
+ locale ?? i18n?.defaultLocale,
47
+ duxt.resolvedSources ?? [],
48
+ fallbackLocale
30
49
  );
31
50
 
32
- const source =
33
- sources.find(
34
- (entry) =>
35
- !entry.prefix ||
36
- wanted === entry.prefix ||
37
- wanted.startsWith(`${entry.prefix}/`)
38
- ) ?? sources[0];
39
-
40
- if (!source) return;
41
-
42
- const page = await queryCollection(
43
- event,
44
- source.collection as Parameters<typeof queryCollection>[1]
45
- )
46
- .path(wanted)
47
- .select('title', 'rawbody')
48
- .first();
51
+ let page;
52
+ for (const source of sources) {
53
+ page = await queryCollection(
54
+ event,
55
+ source.collection as Parameters<typeof queryCollection>[1]
56
+ )
57
+ .path(wanted)
58
+ .select('title', 'rawbody')
59
+ .first();
60
+ if (page) break;
61
+ }
49
62
 
50
63
  // No page is not this middleware's error to raise: falling through lets the
51
64
  // app answer with its own 404, which knows how to suggest a near miss.
@@ -57,30 +70,3 @@ export default defineEventHandler(async (event) => {
57
70
  setHeader(event, 'content-type', 'text/markdown; charset=utf-8');
58
71
  return stripFrontmatter(body).trim();
59
72
  });
60
-
61
- /**
62
- * The locale segment, off.
63
- *
64
- * The browser is on `/de-DE/guide/deploying`; the page is `/guide/deploying`.
65
- * Same distinction `stripLocalePrefix` makes in the app, made again here
66
- * because Nitro has no i18n composable to ask.
67
- */
68
- function stripLocale(path: string): string {
69
- const first = path.split('/')[1];
70
- if (!first) return path;
71
-
72
- const locales = (
73
- useRuntimeConfig().public as {
74
- i18n?: { locales?: ({ code: string } | string)[] };
75
- }
76
- ).i18n?.locales;
77
-
78
- const codes = (locales ?? []).map((locale) =>
79
- typeof locale === 'string' ? locale : locale.code
80
- );
81
-
82
- if (!codes.includes(first)) return path;
83
-
84
- const rest = path.slice(first.length + 1);
85
- return rest.startsWith('/') ? rest : rest || '/';
86
- }
package/sources-git.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { execFileSync } from 'node:child_process';
2
2
  import type { DuxtSource } from './sources-resolve';
3
- import { isLatestRef, newestTag, repoUrl } from './sources-resolve';
3
+ import {
4
+ expandSources,
5
+ isLatestRef,
6
+ newestTag,
7
+ repoUrl
8
+ } from './sources-resolve';
4
9
 
5
10
  /**
6
11
  * Resolve the `latest` shorthand into the tag it means.
@@ -81,6 +86,8 @@ function tagsOf(repo: string | undefined): string[] {
81
86
  * resolver itself stays pure and testable — it never learns that git exists.
82
87
  */
83
88
  export function resolveLatestRefs(sources: DuxtSource[]): DuxtSource[] {
89
+ // Reject local refs before a missing tag can hide the configuration error.
90
+ expandSources(sources);
84
91
  return sources.map((source) => {
85
92
  if (!source.refs?.some(isLatestRef)) return source;
86
93
 
@@ -12,10 +12,10 @@ import type {
12
12
  export interface DuxtSource {
13
13
  /** Folder holding the Markdown, relative to the repository root. */
14
14
  path?: string;
15
- /** `owner/name` or a full git URL. Omitted means this repository. */
15
+ /** `owner/name` or a full git URL. Omitted reads the local checkout. */
16
16
  repo?: string;
17
17
  /**
18
- * Refs to publish as versions. Omitted means the current checkout.
18
+ * Refs to publish as versions. Requires an explicit source or locale repo.
19
19
  *
20
20
  * A bare string is a branch. A tag has to say so — git keeps the two in
21
21
  * separate namespaces, and asking for a tag under refs/heads fails the
@@ -166,7 +166,7 @@ export type DuxtSourceLocale =
166
166
  path?: string;
167
167
  /** A repository of its own — `owner/name` or a git URL. */
168
168
  repo?: string;
169
- /** A ref of its own, when the translation is versioned separately. */
169
+ /** A ref of its own; requires an explicit source or locale repo. */
170
170
  ref?: DuxtRef;
171
171
  };
172
172
 
@@ -488,12 +488,16 @@ export function expandSources(
488
488
 
489
489
  return sources.flatMap((source) =>
490
490
  (source.refs?.length ? source.refs : [undefined]).flatMap((ref) =>
491
- localesOf(source, ref).map((locale) => ({
492
- source,
493
- ref,
494
- locale,
495
- effective: localeEntry(source, locale, defaultLocale)
496
- }))
491
+ localesOf(source, ref).map((locale) => {
492
+ const effective = localeEntry(source, locale, defaultLocale);
493
+ if (!effective.repo && (effective.ref ?? ref)) {
494
+ throw new Error(
495
+ `duxt: source "${source.path ?? 'docs'}" reads the local checkout and cannot select a ref. ` +
496
+ 'Set an explicit repo to publish Git refs, or use version folders without refs.'
497
+ );
498
+ }
499
+ return { source, ref, locale, effective };
500
+ })
497
501
  )
498
502
  );
499
503
  }