nuxtseo-shared 0.1.1 → 0.1.2
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/content.d.mts +39 -39
- package/dist/content.mjs +56 -29
- package/dist/devtools.d.mts +10 -10
- package/dist/devtools.mjs +37 -43
- package/dist/i18n.d.mts +29 -17
- package/dist/i18n.mjs +109 -108
- package/dist/index.d.mts +3 -7
- package/dist/index.mjs +3 -7
- package/dist/kit.d.mts +22 -12
- package/dist/kit.mjs +79 -73
- package/dist/pro.d.mts +7 -7
- package/dist/pro.mjs +64 -64
- package/dist/runtime/app/composables/rpc.d.mts +16 -0
- package/dist/runtime/app/composables/rpc.mjs +28 -0
- package/dist/runtime/app/composables/shiki.d.mts +8 -0
- package/dist/runtime/app/composables/shiki.mjs +31 -0
- package/dist/runtime/app/index.d.mts +2 -0
- package/dist/runtime/app/index.mjs +2 -0
- package/package.json +29 -44
- package/dist/client/composables/rpc.d.mts +0 -21
- package/dist/client/composables/rpc.d.ts +0 -21
- package/dist/client/composables/rpc.mjs +0 -25
- package/dist/client/composables/shiki.d.mts +0 -13
- package/dist/client/composables/shiki.d.ts +0 -13
- package/dist/client/composables/shiki.mjs +0 -39
- package/dist/client/index.d.mts +0 -7
- package/dist/client/index.d.ts +0 -7
- package/dist/client/index.mjs +0 -6
- package/dist/content.d.ts +0 -82
- package/dist/devtools.d.ts +0 -14
- package/dist/i18n.d.ts +0 -32
- package/dist/index.d.ts +0 -7
- package/dist/kit.d.ts +0 -32
- package/dist/pro.d.ts +0 -18
- package/dist/runtime/server/kit.d.mts +0 -7
- package/dist/runtime/server/kit.d.ts +0 -7
- package/dist/runtime/server/kit.mjs +0 -27
- /package/{src/client → dist/runtime/app}/components/NuxtSeoLogo.vue +0 -0
- /package/{src/client → dist/runtime/app}/components/OCodeBlock.vue +0 -0
- /package/{src/client → dist/runtime/app}/components/OSectionBlock.vue +0 -0
package/dist/content.d.mts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
+
//#region src/content.d.ts
|
|
3
4
|
type ZodInstance = typeof z;
|
|
4
5
|
type ZodTypeAny = z.ZodTypeAny;
|
|
5
6
|
interface ContentSchemaOptions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Pass the `z` instance from `@nuxt/content` to ensure `.editor()` works
|
|
9
|
+
* across Zod versions. When omitted, the module's bundled `z` is used.
|
|
10
|
+
*/
|
|
11
|
+
z?: ZodInstance;
|
|
11
12
|
}
|
|
12
13
|
interface ContentEditorConfig {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
hidden?: boolean;
|
|
15
|
+
input?: 'media' | 'icon' | 'textarea';
|
|
16
|
+
iconLibraries?: string[];
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Apply Nuxt Content `.editor()` metadata to a zod schema field.
|
|
@@ -25,23 +26,23 @@ declare function withEditor<T extends ZodTypeAny>(schema: T, config: ContentEdit
|
|
|
25
26
|
*/
|
|
26
27
|
declare function withEditorHidden<T extends ZodTypeAny>(schema: T): T;
|
|
27
28
|
interface DefineContentSchemaConfig<TSchema extends ZodTypeAny> {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The field name used in frontmatter (e.g. 'robots', 'sitemap', 'ogImage').
|
|
31
|
+
*/
|
|
32
|
+
fieldName: string;
|
|
33
|
+
/**
|
|
34
|
+
* Build the zod schema for this field. Receives the zod instance
|
|
35
|
+
* (either the user's `@nuxt/content` patched version or the module's bundled one).
|
|
36
|
+
*/
|
|
37
|
+
buildSchema: (z: ZodInstance) => TSchema;
|
|
38
|
+
/**
|
|
39
|
+
* Module label for deprecation warnings (e.g. 'robots', 'sitemap').
|
|
40
|
+
*/
|
|
41
|
+
label: string;
|
|
42
|
+
/**
|
|
43
|
+
* Documentation URL for migration guidance.
|
|
44
|
+
*/
|
|
45
|
+
docsUrl?: string;
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Factory for creating a module's `define*Schema()` and deprecated `as*Collection()` exports.
|
|
@@ -66,17 +67,16 @@ interface DefineContentSchemaConfig<TSchema extends ZodTypeAny> {
|
|
|
66
67
|
* export { defineSchema as defineRobotsSchema, asCollection as asRobotsCollection, schema }
|
|
67
68
|
*/
|
|
68
69
|
declare function createContentSchemaFactory<TSchema extends ZodTypeAny>(config: DefineContentSchemaConfig<TSchema>, defaultZ: ZodInstance): {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
defineSchema: (options?: ContentSchemaOptions) => TSchema;
|
|
71
|
+
asCollection: <T>(collection: any) => T;
|
|
72
|
+
schema: z.ZodObject<{
|
|
73
|
+
[x: string]: TSchema;
|
|
74
|
+
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
75
|
+
[x: string]: TSchema;
|
|
76
|
+
}>, any> extends infer T ? { [k in keyof T]: T[k] } : never, z.baseObjectInputType<{
|
|
77
|
+
[x: string]: TSchema;
|
|
78
|
+
}> extends infer T_1 ? { [k_1 in keyof T_1]: T_1[k_1] } : never>;
|
|
79
|
+
fieldSchema: TSchema;
|
|
79
80
|
};
|
|
80
|
-
|
|
81
|
-
export { createContentSchemaFactory, withEditor, withEditorHidden };
|
|
82
|
-
export type { ContentEditorConfig, ContentSchemaOptions, DefineContentSchemaConfig };
|
|
81
|
+
//#endregion
|
|
82
|
+
export { ContentEditorConfig, ContentSchemaOptions, DefineContentSchemaConfig, createContentSchemaFactory, withEditor, withEditorHidden };
|
package/dist/content.mjs
CHANGED
|
@@ -1,38 +1,65 @@
|
|
|
1
|
+
//#region src/content.ts
|
|
2
|
+
/**
|
|
3
|
+
* Apply Nuxt Content `.editor()` metadata to a zod schema field.
|
|
4
|
+
* No-ops gracefully when `.editor()` is not patched onto ZodType (outside Nuxt Content).
|
|
5
|
+
*/
|
|
1
6
|
function withEditor(schema, config) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return schema;
|
|
7
|
+
if (typeof schema.editor === "function") return schema.editor(config);
|
|
8
|
+
return schema;
|
|
5
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Hide a zod schema field from the Nuxt Content / Studio editor.
|
|
12
|
+
* Only use for fields that genuinely don't work in a form (freeform JSON, deeply nested arrays).
|
|
13
|
+
*/
|
|
6
14
|
function withEditorHidden(schema) {
|
|
7
|
-
|
|
15
|
+
return withEditor(schema, { hidden: true });
|
|
8
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Factory for creating a module's `define*Schema()` and deprecated `as*Collection()` exports.
|
|
19
|
+
*
|
|
20
|
+
* Each module provides its own schema builder. The factory handles:
|
|
21
|
+
* - Zod instance passthrough for `@nuxt/content` version compatibility
|
|
22
|
+
* - Consistent `DefineSchemaOptions` interface
|
|
23
|
+
* - Deprecated `asXxxCollection()` wrapper with migration warning
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // In @nuxtjs/robots/content.ts
|
|
27
|
+
* import { z } from 'zod'
|
|
28
|
+
* import { createContentSchemaFactory } from 'nuxtseo-shared/content'
|
|
29
|
+
*
|
|
30
|
+
* const { defineSchema, asCollection, schema } = createContentSchemaFactory({
|
|
31
|
+
* fieldName: 'robots',
|
|
32
|
+
* label: 'robots',
|
|
33
|
+
* docsUrl: 'https://nuxtseo.com/robots/guides/content',
|
|
34
|
+
* buildSchema: (z) => z.enum(['index, follow', 'noindex', 'nofollow', 'noindex, nofollow', 'none']).optional(),
|
|
35
|
+
* }, z)
|
|
36
|
+
*
|
|
37
|
+
* export { defineSchema as defineRobotsSchema, asCollection as asRobotsCollection, schema }
|
|
38
|
+
*/
|
|
9
39
|
function createContentSchemaFactory(config, defaultZ) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
schema: schemaObject,
|
|
31
|
-
fieldSchema: defaultSchema
|
|
32
|
-
};
|
|
40
|
+
const { fieldName, buildSchema, label, docsUrl } = config;
|
|
41
|
+
const defaultSchema = buildSchema(defaultZ);
|
|
42
|
+
const schemaObject = defaultZ.object({ [fieldName]: defaultSchema });
|
|
43
|
+
function defineSchema(options) {
|
|
44
|
+
const _z = options?.z ?? defaultZ;
|
|
45
|
+
if (_z === defaultZ) return defaultSchema;
|
|
46
|
+
return buildSchema(_z);
|
|
47
|
+
}
|
|
48
|
+
function asCollection(collection) {
|
|
49
|
+
const migrationHint = docsUrl ? ` See ${docsUrl}` : "";
|
|
50
|
+
console.warn(`[${label}] \`as${capitalize(label)}Collection()\` is deprecated. Use \`define${capitalize(label)}Schema()\` in your collection schema instead.${migrationHint}`);
|
|
51
|
+
if (collection.type === "page") collection.schema = collection.schema ? schemaObject.extend(collection.schema.shape) : schemaObject;
|
|
52
|
+
return collection;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
defineSchema,
|
|
56
|
+
asCollection,
|
|
57
|
+
schema: schemaObject,
|
|
58
|
+
fieldSchema: defaultSchema
|
|
59
|
+
};
|
|
33
60
|
}
|
|
34
61
|
function capitalize(s) {
|
|
35
|
-
|
|
62
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
36
63
|
}
|
|
37
|
-
|
|
64
|
+
//#endregion
|
|
38
65
|
export { createContentSchemaFactory, withEditor, withEditorHidden };
|
package/dist/devtools.d.mts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Resolver } from
|
|
2
|
-
import { Nuxt } from
|
|
1
|
+
import { Resolver } from "@nuxt/kit";
|
|
2
|
+
import { Nuxt } from "nuxt/schema";
|
|
3
3
|
|
|
4
|
+
//#region src/devtools.d.ts
|
|
4
5
|
interface DevToolsUIConfig {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
route: string;
|
|
7
|
+
name: string;
|
|
8
|
+
title: string;
|
|
9
|
+
icon: string;
|
|
10
|
+
devPort?: number;
|
|
10
11
|
}
|
|
11
12
|
declare function setupDevToolsUI(config: DevToolsUIConfig, resolve: Resolver['resolve'], nuxt?: Nuxt): void;
|
|
12
|
-
|
|
13
|
-
export { setupDevToolsUI };
|
|
14
|
-
export type { DevToolsUIConfig };
|
|
13
|
+
//#endregion
|
|
14
|
+
export { DevToolsUIConfig, setupDevToolsUI };
|
package/dist/devtools.mjs
CHANGED
|
@@ -1,46 +1,40 @@
|
|
|
1
|
-
import { existsSync } from
|
|
2
|
-
import { addCustomTab } from
|
|
3
|
-
import { useNuxt } from
|
|
4
|
-
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { addCustomTab } from "@nuxt/devtools-kit";
|
|
3
|
+
import { useNuxt } from "@nuxt/kit";
|
|
4
|
+
//#region src/devtools.ts
|
|
5
5
|
function setupDevToolsUI(config, resolve, nuxt = useNuxt()) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
icon,
|
|
39
|
-
view: {
|
|
40
|
-
type: "iframe",
|
|
41
|
-
src: route
|
|
42
|
-
}
|
|
43
|
-
});
|
|
6
|
+
const { route, name, title, icon, devPort = 3030 } = config;
|
|
7
|
+
const clientPath = resolve("./client");
|
|
8
|
+
if (existsSync(clientPath)) nuxt.hook("vite:serverCreated", async (server) => {
|
|
9
|
+
const sirv = await import("sirv").then((r) => r.default || r);
|
|
10
|
+
server.middlewares.use(route, sirv(clientPath, {
|
|
11
|
+
dev: true,
|
|
12
|
+
single: true
|
|
13
|
+
}));
|
|
14
|
+
});
|
|
15
|
+
else nuxt.hook("vite:extendConfig", (config) => {
|
|
16
|
+
Object.assign(config, { server: {
|
|
17
|
+
...config.server,
|
|
18
|
+
proxy: {
|
|
19
|
+
...config.server?.proxy,
|
|
20
|
+
[route]: {
|
|
21
|
+
target: `http://localhost:${devPort}${route}`,
|
|
22
|
+
changeOrigin: true,
|
|
23
|
+
followRedirects: true,
|
|
24
|
+
rewrite: (p) => p.replace(route, "")
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
} });
|
|
28
|
+
});
|
|
29
|
+
addCustomTab({
|
|
30
|
+
name,
|
|
31
|
+
title,
|
|
32
|
+
icon,
|
|
33
|
+
view: {
|
|
34
|
+
type: "iframe",
|
|
35
|
+
src: route
|
|
36
|
+
}
|
|
37
|
+
});
|
|
44
38
|
}
|
|
45
|
-
|
|
39
|
+
//#endregion
|
|
46
40
|
export { setupDevToolsUI };
|
package/dist/i18n.d.mts
CHANGED
|
@@ -1,32 +1,44 @@
|
|
|
1
|
-
import { LocaleObject, NuxtI18nOptions } from
|
|
1
|
+
import { LocaleObject, NuxtI18nOptions } from "@nuxtjs/i18n";
|
|
2
2
|
|
|
3
|
+
//#region src/i18n.d.ts
|
|
4
|
+
declare const I18N_MODULES: readonly ["@nuxtjs/i18n", "nuxt-i18n-micro"];
|
|
5
|
+
type I18nModuleName = typeof I18N_MODULES[number];
|
|
3
6
|
type Strategies = 'no_prefix' | 'prefix_except_default' | 'prefix' | 'prefix_and_default';
|
|
4
7
|
type NormalisedLocale = LocaleObject & {
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
_sitemap: string;
|
|
9
|
+
_hreflang: string;
|
|
7
10
|
};
|
|
8
11
|
interface AutoI18nConfig {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
locales: NormalisedLocale[];
|
|
13
|
+
defaultLocale: string;
|
|
14
|
+
strategy: Strategies;
|
|
15
|
+
differentDomains?: boolean;
|
|
16
|
+
pages?: Record<string, Record<string, string | false>>;
|
|
14
17
|
}
|
|
15
18
|
interface StrategyProps {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
localeCode: string;
|
|
20
|
+
pageLocales: string;
|
|
21
|
+
nuxtI18nConfig: NuxtI18nOptions;
|
|
22
|
+
forcedStrategy?: Strategies;
|
|
23
|
+
normalisedLocales: AutoI18nConfig['locales'];
|
|
21
24
|
}
|
|
22
25
|
declare function generatePathForI18nPages(ctx: StrategyProps): string;
|
|
23
26
|
declare function splitPathForI18nLocales(path: string, autoI18n: AutoI18nConfig): string | string[];
|
|
24
27
|
declare function normalizeLocales(nuxtI18nConfig: NuxtI18nOptions): AutoI18nConfig['locales'];
|
|
25
28
|
declare function mapPathForI18nPages(path: string, autoI18n: AutoI18nConfig): string[] | false;
|
|
29
|
+
interface I18nModuleResolution {
|
|
30
|
+
module: I18nModuleName;
|
|
31
|
+
isMicro: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Detect which i18n module is installed (@nuxtjs/i18n or nuxt-i18n-micro).
|
|
35
|
+
*
|
|
36
|
+
* Returns `false` when neither is installed.
|
|
37
|
+
*/
|
|
38
|
+
declare function resolveI18nModule(): false | I18nModuleResolution;
|
|
26
39
|
declare function resolveI18nConfig(logger?: {
|
|
27
|
-
|
|
40
|
+
warn: (msg: string) => void;
|
|
28
41
|
}): Promise<false | AutoI18nConfig>;
|
|
29
42
|
declare function mergeOnKey<T extends Record<string, any>>(arr: T[], key: keyof T): T[];
|
|
30
|
-
|
|
31
|
-
export { generatePathForI18nPages, mapPathForI18nPages, mergeOnKey, normalizeLocales, resolveI18nConfig, splitPathForI18nLocales };
|
|
32
|
-
export type { AutoI18nConfig, NormalisedLocale, Strategies, StrategyProps };
|
|
43
|
+
//#endregion
|
|
44
|
+
export { AutoI18nConfig, I18nModuleResolution, NormalisedLocale, Strategies, StrategyProps, generatePathForI18nPages, mapPathForI18nPages, mergeOnKey, normalizeLocales, resolveI18nConfig, resolveI18nModule, splitPathForI18nLocales };
|
package/dist/i18n.mjs
CHANGED
|
@@ -1,121 +1,122 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { getNuxtModuleOptions } from "./kit.mjs";
|
|
2
|
+
import { getNuxtModuleVersion, hasNuxtModule, hasNuxtModuleCompatibility } from "@nuxt/kit";
|
|
3
|
+
import { joinURL, withBase, withHttps, withLeadingSlash } from "ufo";
|
|
4
|
+
//#region src/i18n.ts
|
|
5
|
+
const I18N_MODULES = ["@nuxtjs/i18n", "nuxt-i18n-micro"];
|
|
7
6
|
const SLASH_PATTERN = /^\/|\/$/g;
|
|
8
7
|
function generatePathForI18nPages(ctx) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
const { localeCode, pageLocales, nuxtI18nConfig, forcedStrategy, normalisedLocales } = ctx;
|
|
9
|
+
const locale = normalisedLocales.find((l) => l.code === localeCode);
|
|
10
|
+
let path = pageLocales;
|
|
11
|
+
switch (forcedStrategy ?? nuxtI18nConfig.strategy) {
|
|
12
|
+
case "prefix_except_default":
|
|
13
|
+
case "prefix_and_default":
|
|
14
|
+
path = localeCode === nuxtI18nConfig.defaultLocale ? pageLocales : joinURL(localeCode, pageLocales);
|
|
15
|
+
break;
|
|
16
|
+
case "prefix":
|
|
17
|
+
path = joinURL(localeCode, pageLocales);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
return locale?.domain ? withHttps(withBase(path, locale.domain)) : path;
|
|
22
21
|
}
|
|
23
22
|
function splitPathForI18nLocales(path, autoI18n) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (hasLocalePrefix)
|
|
29
|
-
return path;
|
|
30
|
-
return [
|
|
31
|
-
path,
|
|
32
|
-
...locales.map((l) => `/${l.code}${path}`)
|
|
33
|
-
];
|
|
23
|
+
const locales = autoI18n.strategy === "prefix_except_default" ? autoI18n.locales.filter((l) => l.code !== autoI18n.defaultLocale) : autoI18n.locales;
|
|
24
|
+
if (!path || path.startsWith("/_")) return path;
|
|
25
|
+
if (locales.some((l) => path.startsWith(`/${l.code}/`) || path === `/${l.code}`)) return path;
|
|
26
|
+
return [path, ...locales.map((l) => `/${l.code}${path}`)];
|
|
34
27
|
}
|
|
35
28
|
function normalizeLocales(nuxtI18nConfig) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
const rawLocales = nuxtI18nConfig.locales || [];
|
|
30
|
+
let onlyLocales = nuxtI18nConfig?.bundle?.onlyLocales || [];
|
|
31
|
+
onlyLocales = typeof onlyLocales === "string" ? [onlyLocales] : onlyLocales;
|
|
32
|
+
let locales = mergeOnKey(rawLocales.map((locale) => typeof locale === "string" ? { code: locale } : locale), "code");
|
|
33
|
+
if (onlyLocales.length) locales = locales.filter((locale) => onlyLocales.includes(locale.code));
|
|
34
|
+
return locales.map((locale) => {
|
|
35
|
+
if (typeof locale.iso === "string" && !locale.language) locale.language = locale.iso;
|
|
36
|
+
const _hreflang = locale.language || locale.code;
|
|
37
|
+
const _sitemap = locale.language || locale.code;
|
|
38
|
+
return {
|
|
39
|
+
...locale,
|
|
40
|
+
_hreflang,
|
|
41
|
+
_sitemap
|
|
42
|
+
};
|
|
43
|
+
});
|
|
51
44
|
}
|
|
52
45
|
function mapPathForI18nPages(path, autoI18n) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
46
|
+
const pages = autoI18n.pages;
|
|
47
|
+
if (!pages || !Object.keys(pages).length) return false;
|
|
48
|
+
const withoutSlashes = path.replace(SLASH_PATTERN, "").replace("/index", "");
|
|
49
|
+
function resolveForAllLocales(pageName, pageLocales) {
|
|
50
|
+
return autoI18n.locales.filter((l) => {
|
|
51
|
+
if (l.code in pageLocales && pageLocales[l.code] === false) return false;
|
|
52
|
+
if (autoI18n.strategy === "prefix_except_default" && l.code === autoI18n.defaultLocale) return false;
|
|
53
|
+
return true;
|
|
54
|
+
}).map((l) => {
|
|
55
|
+
const localePath = l.code in pageLocales && pageLocales[l.code] !== false ? pageLocales[l.code] : `/${pageName}`;
|
|
56
|
+
return withLeadingSlash(generatePathForI18nPages({
|
|
57
|
+
localeCode: l.code,
|
|
58
|
+
pageLocales: localePath,
|
|
59
|
+
nuxtI18nConfig: {
|
|
60
|
+
strategy: autoI18n.strategy,
|
|
61
|
+
defaultLocale: autoI18n.defaultLocale
|
|
62
|
+
},
|
|
63
|
+
normalisedLocales: autoI18n.locales
|
|
64
|
+
}));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (withoutSlashes in pages) {
|
|
68
|
+
const pageLocales = pages[withoutSlashes];
|
|
69
|
+
if (pageLocales) return resolveForAllLocales(withoutSlashes, pageLocales);
|
|
70
|
+
}
|
|
71
|
+
for (const [pageName, pageLocales] of Object.entries(pages)) {
|
|
72
|
+
if (!pageLocales) continue;
|
|
73
|
+
if (autoI18n.defaultLocale in pageLocales && pageLocales[autoI18n.defaultLocale] === path) return resolveForAllLocales(pageName, pageLocales);
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Detect which i18n module is installed (@nuxtjs/i18n or nuxt-i18n-micro).
|
|
79
|
+
*
|
|
80
|
+
* Returns `false` when neither is installed.
|
|
81
|
+
*/
|
|
82
|
+
function resolveI18nModule() {
|
|
83
|
+
const found = I18N_MODULES.find((m) => hasNuxtModule(m));
|
|
84
|
+
if (!found) return false;
|
|
85
|
+
return {
|
|
86
|
+
module: found,
|
|
87
|
+
isMicro: found === "nuxt-i18n-micro"
|
|
88
|
+
};
|
|
86
89
|
}
|
|
87
90
|
async function resolveI18nConfig(logger) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
pages: nuxtI18nConfig.pages
|
|
106
|
-
};
|
|
91
|
+
const i18n = resolveI18nModule();
|
|
92
|
+
if (!i18n) return false;
|
|
93
|
+
if (!i18n.isMicro) {
|
|
94
|
+
const i18nVersion = await getNuxtModuleVersion(i18n.module);
|
|
95
|
+
if (!await hasNuxtModuleCompatibility(i18n.module, ">=8")) logger?.warn(`You are using ${i18n.module} v${i18nVersion}. For the best compatibility, please upgrade to ${i18n.module} v8.0.0 or higher.`);
|
|
96
|
+
}
|
|
97
|
+
const nuxtI18nConfig = await getNuxtModuleOptions(i18n.module) || {};
|
|
98
|
+
const normalisedLocales = normalizeLocales(nuxtI18nConfig);
|
|
99
|
+
const usingI18nPages = Object.keys(nuxtI18nConfig.pages || {}).length;
|
|
100
|
+
if (!(nuxtI18nConfig.differentDomains || usingI18nPages || nuxtI18nConfig.strategy !== "no_prefix" && nuxtI18nConfig.locales)) return false;
|
|
101
|
+
return {
|
|
102
|
+
differentDomains: nuxtI18nConfig.differentDomains,
|
|
103
|
+
defaultLocale: nuxtI18nConfig.defaultLocale,
|
|
104
|
+
locales: normalisedLocales,
|
|
105
|
+
strategy: nuxtI18nConfig.strategy,
|
|
106
|
+
pages: nuxtI18nConfig.pages
|
|
107
|
+
};
|
|
107
108
|
}
|
|
108
109
|
function mergeOnKey(arr, key) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
110
|
+
const map = /* @__PURE__ */ new Map();
|
|
111
|
+
for (const item of arr) {
|
|
112
|
+
const k = item[key];
|
|
113
|
+
if (map.has(k)) map.set(k, {
|
|
114
|
+
...map.get(k),
|
|
115
|
+
...item
|
|
116
|
+
});
|
|
117
|
+
else map.set(k, item);
|
|
118
|
+
}
|
|
119
|
+
return [...map.values()];
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
-
export { generatePathForI18nPages, mapPathForI18nPages, mergeOnKey, normalizeLocales, resolveI18nConfig, splitPathForI18nLocales };
|
|
121
|
+
//#endregion
|
|
122
|
+
export { generatePathForI18nPages, mapPathForI18nPages, mergeOnKey, normalizeLocales, resolveI18nConfig, resolveI18nModule, splitPathForI18nLocales };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import 'nuxt/schema';
|
|
5
|
-
import '@nuxt/schema';
|
|
6
|
-
import 'nitropack';
|
|
7
|
-
import 'nitropack/types';
|
|
1
|
+
import { setupDevToolsUI } from "./devtools.mjs";
|
|
2
|
+
import { NuxtContentVersion, createNitroPromise, createPagesPromise, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveNitroPreset, resolveNuxtContentVersion } from "./kit.mjs";
|
|
3
|
+
export { type NuxtContentVersion, createNitroPromise, createPagesPromise, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveNitroPreset, resolveNuxtContentVersion, setupDevToolsUI };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import '@nuxt/devtools-kit';
|
|
5
|
-
import '@nuxt/kit';
|
|
6
|
-
import 'pathe';
|
|
7
|
-
import 'std-env';
|
|
1
|
+
import { setupDevToolsUI } from "./devtools.mjs";
|
|
2
|
+
import { createNitroPromise, createPagesPromise, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveNitroPreset, resolveNuxtContentVersion } from "./kit.mjs";
|
|
3
|
+
export { createNitroPromise, createPagesPromise, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveNitroPreset, resolveNuxtContentVersion, setupDevToolsUI };
|