@kirchdev/duxt 0.1.1-dev.17-509021b → 0.1.1-dev.19-efe898e
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.
|
|
4
|
+
"version": "0.1.1-dev.19-efe898e",
|
|
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
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
}
|
|
@@ -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
|
+
}
|