@kirchdev/duxt 0.1.1-dev.17-509021b → 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.
|
|
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
|
|
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
|
-
}
|