@kirchdev/duxt 0.1.1-dev.18-c374611 → 0.1.1-dev.20-23ef74a
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.
|
@@ -45,6 +45,8 @@ export function versionChoices(
|
|
|
45
45
|
// from the URL segment.
|
|
46
46
|
if (configured?.length) return configured;
|
|
47
47
|
|
|
48
|
+
const editions = new Set<string>();
|
|
49
|
+
|
|
48
50
|
return sources
|
|
49
51
|
.filter(
|
|
50
52
|
(source) =>
|
|
@@ -52,6 +54,14 @@ export function versionChoices(
|
|
|
52
54
|
source.repo === current?.repo &&
|
|
53
55
|
sameArtefact(source, current)
|
|
54
56
|
)
|
|
57
|
+
.filter((source) => {
|
|
58
|
+
// Repository and artefact are scoped above; translations share the
|
|
59
|
+
// edition's version and target, while keeping separate collections.
|
|
60
|
+
const edition = JSON.stringify([source.version, source.prefix || '/']);
|
|
61
|
+
if (editions.has(edition)) return false;
|
|
62
|
+
editions.add(edition);
|
|
63
|
+
return true;
|
|
64
|
+
})
|
|
55
65
|
.map((source) => ({
|
|
56
66
|
label: source.version!,
|
|
57
67
|
to: source.prefix || '/',
|
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.
|
|
4
|
+
"version": "0.1.1-dev.20-23ef74a",
|
|
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,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { llmsPages } from '../utils/llms-pages';
|
|
2
2
|
// Imported by path, not auto-import: app/ belongs to the Vue app, and Nitro
|
|
3
3
|
// does not see its utils. The defaults have to come from the same file the
|
|
4
4
|
// pages use, or the two descriptions drift apart.
|
|
@@ -27,19 +27,7 @@ export default defineEventHandler(async (event) => {
|
|
|
27
27
|
mergeDuxtConfig(appConfig.duxt, duxtDefaults)
|
|
28
28
|
);
|
|
29
29
|
|
|
30
|
-
const
|
|
31
|
-
? duxt.resolvedSources.map((source) => source.collection)
|
|
32
|
-
: ['docs'];
|
|
33
|
-
|
|
34
|
-
const pages = (
|
|
35
|
-
await Promise.all(
|
|
36
|
-
collections.map((name) =>
|
|
37
|
-
queryCollection(event, name as Parameters<typeof queryCollection>[1])
|
|
38
|
-
.select('path', 'title', 'description', 'rawbody')
|
|
39
|
-
.all()
|
|
40
|
-
)
|
|
41
|
-
)
|
|
42
|
-
).flat();
|
|
30
|
+
const pages = await llmsPages(event, duxt.resolvedSources);
|
|
43
31
|
|
|
44
32
|
const origin = getRequestURL(event).origin;
|
|
45
33
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { llmsPages } from '../utils/llms-pages';
|
|
2
2
|
// Imported by path, not auto-import: app/ belongs to the Vue app, and Nitro
|
|
3
3
|
// does not see its utils. The defaults have to come from the same file the
|
|
4
4
|
// pages use, or the two descriptions drift apart.
|
|
@@ -22,21 +22,7 @@ export default defineEventHandler(async (event) => {
|
|
|
22
22
|
|
|
23
23
|
// Every collection the manifest names, not just `docs`: a versioned site
|
|
24
24
|
// has none by that name, and llms.txt is the whole site's index.
|
|
25
|
-
const
|
|
26
|
-
? duxt.resolvedSources.map((source) => source.collection)
|
|
27
|
-
: ['docs'];
|
|
28
|
-
|
|
29
|
-
const pages = (
|
|
30
|
-
await Promise.all(
|
|
31
|
-
collections.map((name) =>
|
|
32
|
-
// Cast from Content's own signature: the collection name is data
|
|
33
|
-
// from the manifest, and the key union is generated per site.
|
|
34
|
-
queryCollection(event, name as Parameters<typeof queryCollection>[1])
|
|
35
|
-
.select('path', 'title', 'description')
|
|
36
|
-
.all()
|
|
37
|
-
)
|
|
38
|
-
)
|
|
39
|
-
).flat();
|
|
25
|
+
const pages = await llmsPages(event, duxt.resolvedSources);
|
|
40
26
|
|
|
41
27
|
const origin = getRequestURL(event).origin;
|
|
42
28
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { queryCollection } from '@nuxt/content/nitro';
|
|
2
|
+
import type { H3Event } from 'h3';
|
|
3
|
+
import {
|
|
4
|
+
sourcesForRoute,
|
|
5
|
+
type DuxtResolvedSource
|
|
6
|
+
} from '../../sources-resolve';
|
|
7
|
+
|
|
8
|
+
/** Enumerate public pages, selecting the same collection chain as HTML. */
|
|
9
|
+
export async function llmsPages(
|
|
10
|
+
event: H3Event,
|
|
11
|
+
sources: DuxtResolvedSource[] = []
|
|
12
|
+
) {
|
|
13
|
+
const i18n = (
|
|
14
|
+
useRuntimeConfig(event).public as unknown as {
|
|
15
|
+
i18n?: {
|
|
16
|
+
locales?: (string | { code: string })[];
|
|
17
|
+
defaultLocale?: string;
|
|
18
|
+
strategy?: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
).i18n;
|
|
22
|
+
const fallbackLocale = event.context.nuxtI18n?.vueI18nOptions
|
|
23
|
+
?.fallbackLocale as string | string[] | undefined;
|
|
24
|
+
const codes = (i18n?.locales ?? []).map((locale) =>
|
|
25
|
+
typeof locale === 'string' ? locale : locale.code
|
|
26
|
+
);
|
|
27
|
+
const defaultLocale = i18n?.defaultLocale ?? codes[0];
|
|
28
|
+
const strategy = i18n?.strategy ?? 'prefix_except_default';
|
|
29
|
+
const locales =
|
|
30
|
+
strategy === 'no_prefix' || !codes.length ? [defaultLocale] : codes;
|
|
31
|
+
const collections = sources.length
|
|
32
|
+
? [...new Set(sources.map((source) => source.collection))]
|
|
33
|
+
: ['docs'];
|
|
34
|
+
const entries = await Promise.all(
|
|
35
|
+
collections.map(
|
|
36
|
+
async (name) =>
|
|
37
|
+
[
|
|
38
|
+
name,
|
|
39
|
+
await queryCollection(
|
|
40
|
+
event,
|
|
41
|
+
name as Parameters<typeof queryCollection>[1]
|
|
42
|
+
)
|
|
43
|
+
.select('path', 'title', 'description', 'rawbody')
|
|
44
|
+
.all()
|
|
45
|
+
] as const
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
const pagesByCollection = new Map(
|
|
49
|
+
entries.map(([name, pages]) => [
|
|
50
|
+
name,
|
|
51
|
+
new Map(
|
|
52
|
+
pages.filter((page) => page.path).map((page) => [page.path, page])
|
|
53
|
+
)
|
|
54
|
+
])
|
|
55
|
+
);
|
|
56
|
+
const paths = new Set(
|
|
57
|
+
entries.flatMap(([, pages]) =>
|
|
58
|
+
pages.map((page) => page.path).filter(Boolean)
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
const result = new Map<string, (typeof entries)[number][1][number]>();
|
|
62
|
+
|
|
63
|
+
for (const locale of locales) {
|
|
64
|
+
for (const path of paths) {
|
|
65
|
+
const chain = sources.length
|
|
66
|
+
? sourcesForRoute(path, locale, sources, fallbackLocale).map(
|
|
67
|
+
(source) => source.collection
|
|
68
|
+
)
|
|
69
|
+
: ['docs'];
|
|
70
|
+
const page = chain
|
|
71
|
+
.map((name) => pagesByCollection.get(name)?.get(path))
|
|
72
|
+
.find(Boolean);
|
|
73
|
+
if (!page) continue;
|
|
74
|
+
const prefixed =
|
|
75
|
+
locale &&
|
|
76
|
+
strategy !== 'no_prefix' &&
|
|
77
|
+
(strategy !== 'prefix_except_default' || locale !== defaultLocale);
|
|
78
|
+
const publicPath = prefixed
|
|
79
|
+
? `/${locale}${path === '/' ? '' : path}`
|
|
80
|
+
: path;
|
|
81
|
+
result.set(publicPath, { ...page, path: publicPath });
|
|
82
|
+
if (strategy === 'prefix_and_default' && locale === defaultLocale)
|
|
83
|
+
result.set(path, { ...page, path });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return [...result.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
87
|
+
}
|