@i18n-micro/vitepress 1.1.1 → 1.1.6

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.
Files changed (41) hide show
  1. package/dist/adapter-CAJNI6Sw.js +127 -0
  2. package/dist/adapter-CAJNI6Sw.js.map +1 -0
  3. package/dist/adapter-eYZZOC9d.cjs +2 -0
  4. package/dist/adapter-eYZZOC9d.cjs.map +1 -0
  5. package/dist/config.cjs +13 -19
  6. package/dist/config.cjs.map +1 -1
  7. package/dist/config.mjs +329 -336
  8. package/dist/config.mjs.map +1 -1
  9. package/dist/create-C_dXg23X.js +81 -0
  10. package/dist/create-C_dXg23X.js.map +1 -0
  11. package/dist/create-Cwu2djcO.cjs +2 -0
  12. package/dist/create-Cwu2djcO.cjs.map +1 -0
  13. package/dist/index.cjs +2 -2
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.mjs +20 -31
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/node.cjs +2 -2
  18. package/dist/node.cjs.map +1 -1
  19. package/dist/node.mjs +22 -25
  20. package/dist/node.mjs.map +1 -1
  21. package/dist/theme.cjs +2 -2
  22. package/dist/theme.cjs.map +1 -1
  23. package/dist/theme.mjs +35 -34
  24. package/dist/theme.mjs.map +1 -1
  25. package/dist/vitepress-locales-CwOlvAa0.cjs +2 -0
  26. package/dist/vitepress-locales-CwOlvAa0.cjs.map +1 -0
  27. package/dist/vitepress-locales-DOhKs3q5.js +27 -0
  28. package/dist/vitepress-locales-DOhKs3q5.js.map +1 -0
  29. package/package.json +14 -14
  30. package/dist/adapter-BJ-0ltIc.cjs +0 -2
  31. package/dist/adapter-BJ-0ltIc.cjs.map +0 -1
  32. package/dist/adapter-BnsyIKhp.js +0 -128
  33. package/dist/adapter-BnsyIKhp.js.map +0 -1
  34. package/dist/create-BgMbe0w1.cjs +0 -2
  35. package/dist/create-BgMbe0w1.cjs.map +0 -1
  36. package/dist/create-Dev8Q66O.js +0 -80
  37. package/dist/create-Dev8Q66O.js.map +0 -1
  38. package/dist/vitepress-locales-6msv22Sn.js +0 -27
  39. package/dist/vitepress-locales-6msv22Sn.js.map +0 -1
  40. package/dist/vitepress-locales-Cz4AutfI.cjs +0 -2
  41. package/dist/vitepress-locales-Cz4AutfI.cjs.map +0 -1
package/dist/config.mjs CHANGED
@@ -1,29 +1,26 @@
1
- import { existsSync as I, readdirSync as G, statSync as Q, readFileSync as z } from "node:fs";
2
- import { resolve as W, join as X, relative as F, sep as J } from "node:path";
3
- import { storeLoadedTranslationFile as Y, classifyTranslationRelativePath as Z } from "@i18n-micro/utils/parse-path";
4
- import { resolveHreflangAlternates as ee } from "@i18n-micro/utils/resolve-hreflang";
5
- import { resolveOgLocale as B, warnUnresolvedOgLocale as D } from "@i18n-micro/utils/resolve-og-locale";
6
- import { s as te, g as ae } from "./adapter-BnsyIKhp.js";
7
- import { b as ve } from "./vitepress-locales-6msv22Sn.js";
8
- function oe(e) {
9
- return "switchLocalePath" in e && typeof e.switchLocalePath == "function";
1
+ import { i as e, n as t } from "./adapter-CAJNI6Sw.js";
2
+ import { t as n } from "./vitepress-locales-DOhKs3q5.js";
3
+ import { classifyTranslationRelativePath as r, storeLoadedTranslationFile as i } from "@i18n-micro/utils/parse-path";
4
+ import { existsSync as a, readFileSync as o, readdirSync as s, statSync as c } from "node:fs";
5
+ import { join as l, relative as u, resolve as d, sep as f } from "node:path";
6
+ import { resolveHreflangAlternates as p } from "@i18n-micro/utils/resolve-hreflang";
7
+ import { resolveOgLocale as m, warnUnresolvedOgLocale as h } from "@i18n-micro/utils/resolve-og-locale";
8
+ //#region src/router/i18n-routing.ts
9
+ function g(e) {
10
+ return "switchLocalePath" in e && typeof e.switchLocalePath == "function";
10
11
  }
11
- function U(e) {
12
- const t = oe(e) ? {
13
- defaultLocale: e.defaultLocale,
14
- localeCodes: e.localeCodes,
15
- localeKeyToCode: e.localeKeyToCode ?? {},
16
- base: e.base
17
- } : e, a = t.defaultLocale, o = t.localeCodes, s = t.localeKeyToCode ?? {}, l = t.base && t.base !== "/" ? t.base : "";
18
- return new Function(
19
- "data",
20
- "route",
21
- "targetLocale",
22
- `
23
- const defaultLocale = ${JSON.stringify(a)};
24
- const localeCodes = ${JSON.stringify(o)};
25
- const localeKeyToCode = ${JSON.stringify(s)};
26
- const siteBase = ${JSON.stringify(l)};
12
+ function _(e) {
13
+ let t = g(e) ? {
14
+ defaultLocale: e.defaultLocale,
15
+ localeCodes: e.localeCodes,
16
+ localeKeyToCode: e.localeKeyToCode ?? {},
17
+ base: e.base
18
+ } : e, n = t.defaultLocale, r = t.localeCodes, i = t.localeKeyToCode ?? {}, a = t.base && t.base !== "/" ? t.base : "";
19
+ return Function("data", "route", "targetLocale", `
20
+ const defaultLocale = ${JSON.stringify(n)};
21
+ const localeCodes = ${JSON.stringify(r)};
22
+ const localeKeyToCode = ${JSON.stringify(i)};
23
+ const siteBase = ${JSON.stringify(a)};
27
24
  const keyFromCode = (code) => {
28
25
  for (const key of Object.keys(localeKeyToCode)) {
29
26
  if (localeKeyToCode[key] === code) return key;
@@ -69,328 +66,324 @@ function U(e) {
69
66
  ? (hash.charAt(0) === '#' ? hash : '#' + hash)
70
67
  : '';
71
68
  return localized + extras + q + h;
72
- `
73
- );
69
+ `);
74
70
  }
75
- function se(e, t) {
76
- const a = e.indexOf("#"), o = e.indexOf("?");
77
- let s = e.length;
78
- a >= 0 && (s = Math.min(s, a)), o >= 0 && (s = Math.min(s, o));
79
- const l = e.slice(0, s) || "/";
80
- if (o < 0 || t.length === 0) return l;
81
- const n = new URLSearchParams(e.slice(o, a >= 0 ? a : void 0)), i = new URLSearchParams();
82
- for (const f of t)
83
- n.has(f) && i.set(f, n.get(f));
84
- const h = i.toString();
85
- return h ? `${l}?${h}` : l;
71
+ //#endregion
72
+ //#region src/seo/locale-head.ts
73
+ function v(e, t) {
74
+ let n = e.indexOf("#"), r = e.indexOf("?"), i = e.length;
75
+ n >= 0 && (i = Math.min(i, n)), r >= 0 && (i = Math.min(i, r));
76
+ let a = e.slice(0, i) || "/";
77
+ if (r < 0 || t.length === 0) return a;
78
+ let o = new URLSearchParams(e.slice(r, n >= 0 ? n : void 0)), s = new URLSearchParams();
79
+ for (let e of t) o.has(e) && s.set(e, o.get(e));
80
+ let c = s.toString();
81
+ return c ? `${a}?${c}` : a;
86
82
  }
87
- function N(e, t, a) {
88
- const o = e.replace(/\/$/, ""), s = !t || t === "/" ? "" : t.replace(/\/$/, ""), l = a.startsWith("/") ? a : `/${a}`;
89
- return `${o}${s}${l}`;
83
+ function y(e, t, n) {
84
+ return `${e.replace(/\/$/, "")}${!t || t === "/" ? "" : t.replace(/\/$/, "")}${n.startsWith("/") ? n : `/${n}`}`;
90
85
  }
91
- function R(e) {
92
- let t = e.replace(/\\/g, "/");
93
- return t = t.replace(/(^|\/)index\.md$/, "$1").replace(/\.md$/, ""), t.startsWith("/") || (t = `/${t}`), t.length > 1 && t.endsWith("/") && (t = t.slice(0, -1)), t || "/";
86
+ function b(e) {
87
+ let t = e.replace(/\\/g, "/");
88
+ return t = t.replace(/(^|\/)index\.md$/, "$1").replace(/\.md$/, ""), t.startsWith("/") || (t = `/${t}`), t.length > 1 && t.endsWith("/") && (t = t.slice(0, -1)), t || "/";
94
89
  }
95
- function E(e) {
96
- const {
97
- locales: t,
98
- defaultLocale: a,
99
- localeKeyToCode: o = {},
100
- base: s,
101
- metaBaseUrl: l,
102
- hreflangBaseLanguage: n = !1,
103
- canonicalQueryWhitelist: i = [],
104
- addDirAttribute: h = !0,
105
- addSeoAttributes: f = !0,
106
- identifierAttribute: u = "id",
107
- missingWarn: m = !0
108
- } = e, g = te(e.path, s), r = ae(
109
- g,
110
- t.map((c) => c.code),
111
- a,
112
- o,
113
- void 0
114
- ), y = t.find((c) => c.code === r);
115
- if (!y)
116
- return { htmlAttrs: {}, head: [] };
117
- const b = y.iso || r, p = y.dir || "auto", P = {
118
- lang: b,
119
- ...h ? { dir: p } : {}
120
- };
121
- if (!f || !l)
122
- return { htmlAttrs: P, head: [] };
123
- const d = U({
124
- defaultLocale: a,
125
- localeCodes: t.map((c) => c.code),
126
- localeKeyToCode: o,
127
- base: s
128
- }), x = se(g, i), v = r === a ? "root" : (() => {
129
- for (const [c, L] of Object.entries(o))
130
- if (L === r) return c === "root" ? "root" : c;
131
- return r;
132
- })(), M = d({}, { path: x }, v), T = N(l, s, M), $ = t.filter((c) => !c.disabled && c.seo !== !1), k = B(y);
133
- k || D(y, { missingWarn: m, tag: "og:locale" });
134
- const C = [];
135
- C.push(["link", { [u]: "i18n-can", rel: "canonical", href: T }]), k && C.push(["meta", { [u]: "i18n-og", property: "og:locale", content: k }]), C.push(["meta", { [u]: "i18n-og-url", property: "og:url", content: T }]);
136
- for (const c of $) {
137
- if (c.code === r) continue;
138
- const L = B(c);
139
- if (!L) {
140
- D(c, { missingWarn: m, tag: "og:locale:alternate" });
141
- continue;
142
- }
143
- C.push(["meta", { [u]: `i18n-og-alt-${L}`, property: "og:locale:alternate", content: L }]);
144
- }
145
- const A = /* @__PURE__ */ new Map();
146
- for (const c of $) {
147
- const L = c.code === a ? "root" : (() => {
148
- for (const [O, H] of Object.entries(o))
149
- if (H === c.code) return O === "root" ? c.code : O;
150
- return c.code;
151
- })(), S = d({}, { path: x }, L);
152
- S && A.set(String(c.code), N(l, s, S));
153
- }
154
- for (const { hreflang: c, localeCode: L } of ee($, { hreflangBaseLanguage: n })) {
155
- const S = A.get(L);
156
- S && C.push(["link", { [u]: `i18n-alternate-${c}`, rel: "alternate", href: S, hreflang: c }]);
157
- }
158
- const K = t.find((c) => c.code === a);
159
- if (K && K.seo !== !1) {
160
- const c = A.get(a);
161
- c && C.push(["link", { [u]: "i18n-xd", rel: "alternate", href: c, hreflang: "x-default" }]);
162
- }
163
- return { htmlAttrs: P, head: C };
90
+ function x(n) {
91
+ let { locales: r, defaultLocale: i, localeKeyToCode: a = {}, base: o, metaBaseUrl: s, hreflangBaseLanguage: c = !1, canonicalQueryWhitelist: l = [], addDirAttribute: u = !0, addSeoAttributes: d = !0, identifierAttribute: f = "id", missingWarn: g = !0 } = n, b = e(n.path, o), x = t(b, r.map((e) => e.code), i, a, void 0), S = r.find((e) => e.code === x);
92
+ if (!S) return {
93
+ htmlAttrs: {},
94
+ head: []
95
+ };
96
+ let C = S.iso || x, w = S.dir || "auto", T = {
97
+ lang: C,
98
+ ...u ? { dir: w } : {}
99
+ };
100
+ if (!d || !s) return {
101
+ htmlAttrs: T,
102
+ head: []
103
+ };
104
+ let E = _({
105
+ defaultLocale: i,
106
+ localeCodes: r.map((e) => e.code),
107
+ localeKeyToCode: a,
108
+ base: o
109
+ }), D = v(b, l), O = x === i ? "root" : (() => {
110
+ for (let [e, t] of Object.entries(a)) if (t === x) return e === "root" ? "root" : e;
111
+ return x;
112
+ })(), k = y(s, o, E({}, { path: D }, O)), A = r.filter((e) => !e.disabled && e.seo !== !1), j = m(S);
113
+ j || h(S, {
114
+ missingWarn: g,
115
+ tag: "og:locale"
116
+ });
117
+ let M = [];
118
+ M.push(["link", {
119
+ [f]: "i18n-can",
120
+ rel: "canonical",
121
+ href: k
122
+ }]), j && M.push(["meta", {
123
+ [f]: "i18n-og",
124
+ property: "og:locale",
125
+ content: j
126
+ }]), M.push(["meta", {
127
+ [f]: "i18n-og-url",
128
+ property: "og:url",
129
+ content: k
130
+ }]);
131
+ for (let e of A) {
132
+ if (e.code === x) continue;
133
+ let t = m(e);
134
+ if (!t) {
135
+ h(e, {
136
+ missingWarn: g,
137
+ tag: "og:locale:alternate"
138
+ });
139
+ continue;
140
+ }
141
+ M.push(["meta", {
142
+ [f]: `i18n-og-alt-${t}`,
143
+ property: "og:locale:alternate",
144
+ content: t
145
+ }]);
146
+ }
147
+ let N = /* @__PURE__ */ new Map();
148
+ for (let e of A) {
149
+ let t = e.code === i ? "root" : (() => {
150
+ for (let [t, n] of Object.entries(a)) if (n === e.code) return t === "root" ? e.code : t;
151
+ return e.code;
152
+ })(), n = E({}, { path: D }, t);
153
+ n && N.set(String(e.code), y(s, o, n));
154
+ }
155
+ for (let { hreflang: e, localeCode: t } of p(A, { hreflangBaseLanguage: c })) {
156
+ let n = N.get(t);
157
+ n && M.push(["link", {
158
+ [f]: `i18n-alternate-${e}`,
159
+ rel: "alternate",
160
+ href: n,
161
+ hreflang: e
162
+ }]);
163
+ }
164
+ let P = r.find((e) => e.code === i);
165
+ if (P && P.seo !== !1) {
166
+ let e = N.get(i);
167
+ e && M.push(["link", {
168
+ [f]: "i18n-xd",
169
+ rel: "alternate",
170
+ href: e,
171
+ hreflang: "x-default"
172
+ }]);
173
+ }
174
+ return {
175
+ htmlAttrs: T,
176
+ head: M
177
+ };
164
178
  }
165
- function j(e, t) {
166
- if (I(e))
167
- for (const a of G(e)) {
168
- const o = X(e, a);
169
- if (Q(o).isDirectory()) {
170
- j(o, t);
171
- continue;
172
- }
173
- a.endsWith(".json") && t(o);
174
- }
179
+ //#endregion
180
+ //#region src/plugin/load-messages.ts
181
+ function S(e, t) {
182
+ if (a(e)) for (let n of s(e)) {
183
+ let r = l(e, n);
184
+ if (c(r).isDirectory()) {
185
+ S(r, t);
186
+ continue;
187
+ }
188
+ n.endsWith(".json") && t(r);
189
+ }
175
190
  }
176
- function re(e) {
177
- const t = e.rootDir ?? process.cwd(), a = W(t, e.translationDir), o = [];
178
- return j(a, (s) => {
179
- o.push({
180
- absolutePath: s,
181
- relativePath: F(a, s).split(J).join("/")
182
- });
183
- }), o.sort((s, l) => s.relativePath.localeCompare(l.relativePath));
191
+ function C(e) {
192
+ let t = e.rootDir ?? process.cwd(), n = d(t, e.translationDir), r = [];
193
+ return S(n, (e) => {
194
+ r.push({
195
+ absolutePath: e,
196
+ relativePath: u(n, e).split(f).join("/")
197
+ });
198
+ }), r.sort((e, t) => e.relativePath.localeCompare(t.relativePath));
184
199
  }
185
- function ne(e) {
186
- const t = e.rootDir ?? process.cwd(), a = W(t, e.translationDir), o = { root: {}, routes: {} }, s = e.disablePageLocales === !0;
187
- return I(a) && j(a, (l) => {
188
- const n = F(a, l).split(J).join("/");
189
- try {
190
- const i = JSON.parse(z(l, "utf-8"));
191
- if (i === null || typeof i != "object" || Array.isArray(i)) {
192
- console.error(
193
- `[i18n-micro/vitepress] Skipping ${n}: expected a JSON object, got ${Array.isArray(i) ? "array" : typeof i}`
194
- );
195
- return;
196
- }
197
- Y(o, n, i, s);
198
- } catch (i) {
199
- console.error(`[i18n-micro/vitepress] Failed to load ${n}:`, i);
200
- }
201
- }), o;
200
+ function w(e) {
201
+ let t = e.rootDir ?? process.cwd(), n = d(t, e.translationDir), r = {
202
+ root: {},
203
+ routes: {}
204
+ }, s = e.disablePageLocales === !0;
205
+ return a(n) && S(n, (e) => {
206
+ let t = u(n, e).split(f).join("/");
207
+ try {
208
+ let n = JSON.parse(o(e, "utf-8"));
209
+ if (typeof n != "object" || !n || Array.isArray(n)) {
210
+ console.error(`[i18n-micro/vitepress] Skipping ${t}: expected a JSON object, got ${Array.isArray(n) ? "array" : typeof n}`);
211
+ return;
212
+ }
213
+ i(r, t, n, s);
214
+ } catch (e) {
215
+ console.error(`[i18n-micro/vitepress] Failed to load ${t}:`, e);
216
+ }
217
+ }), r;
202
218
  }
203
- const V = "virtual:i18n-micro/config", q = `\0${V}`, _ = "virtual:i18n-micro/messages", w = `\0${_}`;
204
- function ce(e) {
205
- return e.replace(/\\/g, "/");
219
+ //#endregion
220
+ //#region src/plugin/with-i18n.ts
221
+ var T = "virtual:i18n-micro/config", E = `\0${T}`, D = "virtual:i18n-micro/messages", O = `\0${D}`;
222
+ function k(e) {
223
+ return e.replace(/\\/g, "/");
206
224
  }
207
- function le(e, t, a) {
208
- const o = re({ rootDir: e, translationDir: t });
209
- if (o.length === 0)
210
- return `export const messages = {}
211
- export const routeMessages = {}
212
- `;
213
- const s = [], l = [], n = /* @__PURE__ */ new Map();
214
- let i = 0;
215
- for (const f of o) {
216
- const u = Z(f.relativePath, a);
217
- if (u.type === "ignore") continue;
218
- const m = `__i18n_${i++}`;
219
- if (s.push(`import ${m} from ${JSON.stringify(ce(f.absolutePath))}`), u.type === "root") {
220
- l.push(` ${JSON.stringify(u.locale)}: ${m}`);
221
- continue;
222
- }
223
- let g = n.get(u.pageName);
224
- g || (g = /* @__PURE__ */ new Map(), n.set(u.pageName, g)), g.set(u.locale, m);
225
- }
226
- const h = [];
227
- for (const [f, u] of n) {
228
- const m = [...u.entries()].map(([g, r]) => ` ${JSON.stringify(g)}: ${r}`).join(`,
229
- `);
230
- h.push(` ${JSON.stringify(f)}: {
231
- ${m}
232
- }`);
233
- }
234
- return [
235
- ...s,
236
- `export const messages = {
237
- ${l.join(`,
238
- `)}
239
- }`,
240
- `export const routeMessages = {
241
- ${h.join(`,
242
- `)}
243
- }`,
244
- ""
245
- ].join(`
246
- `);
225
+ function A(e, t, n) {
226
+ let i = C({
227
+ rootDir: e,
228
+ translationDir: t
229
+ });
230
+ if (i.length === 0) return "export const messages = {}\nexport const routeMessages = {}\n";
231
+ let a = [], o = [], s = /* @__PURE__ */ new Map(), c = 0;
232
+ for (let e of i) {
233
+ let t = r(e.relativePath, n);
234
+ if (t.type === "ignore") continue;
235
+ let i = `__i18n_${c++}`;
236
+ if (a.push(`import ${i} from ${JSON.stringify(k(e.absolutePath))}`), t.type === "root") {
237
+ o.push(` ${JSON.stringify(t.locale)}: ${i}`);
238
+ continue;
239
+ }
240
+ let l = s.get(t.pageName);
241
+ l || (l = /* @__PURE__ */ new Map(), s.set(t.pageName, l)), l.set(t.locale, i);
242
+ }
243
+ let l = [];
244
+ for (let [e, t] of s) {
245
+ let n = [...t.entries()].map(([e, t]) => ` ${JSON.stringify(e)}: ${t}`).join(",\n");
246
+ l.push(` ${JSON.stringify(e)}: {\n${n}\n }`);
247
+ }
248
+ return [
249
+ ...a,
250
+ `export const messages = {\n${o.join(",\n")}\n}`,
251
+ `export const routeMessages = {\n${l.join(",\n")}\n}`,
252
+ ""
253
+ ].join("\n");
247
254
  }
248
- function ie(e, t) {
249
- return [`export const messages = ${JSON.stringify(e)}`, `export const routeMessages = ${JSON.stringify(t)}`, ""].join(`
250
- `);
255
+ function j(e, t) {
256
+ return [
257
+ `export const messages = ${JSON.stringify(e)}`,
258
+ `export const routeMessages = ${JSON.stringify(t)}`,
259
+ ""
260
+ ].join("\n");
251
261
  }
252
- function ue(e, t) {
253
- const a = e.defaultLocale || e.locale, o = e.translationDir ?? "locales", s = e.disablePageLocales === !0, l = {
254
- defaultLocale: a,
255
- fallbackLocale: e.fallbackLocale || a,
256
- locales: e.locales || [],
257
- localeCodes: (e.locales || []).map((r) => r.code),
258
- missingWarn: e.missingWarn ?? !0,
259
- syncWithVitePress: e.syncWithVitePress !== !1,
260
- translationDir: o,
261
- disablePageLocales: s,
262
- localeKeyToCode: e.localeKeyToCode ?? {},
263
- base: t && t !== "/" ? t : void 0
264
- };
265
- let n = process.cwd(), i = !!(e.messages || e.routeMessages), h = e.messages ?? {}, f = e.routeMessages ?? {}, u;
266
- const m = () => !e.messages || !e.routeMessages, g = () => {
267
- if (!m()) return;
268
- const r = ne({
269
- rootDir: n,
270
- translationDir: o,
271
- disablePageLocales: s
272
- });
273
- e.messages || (h = r.root), e.routeMessages || (f = r.routes);
274
- };
275
- return {
276
- name: "vite-plugin-i18n-vitepress",
277
- configResolved(r) {
278
- n = r.root, i = !!(e.messages || e.routeMessages), i && (e.messages && (h = e.messages), e.routeMessages && (f = e.routeMessages), m() && g(), e.messages && (h = e.messages), e.routeMessages && (f = e.routeMessages));
279
- },
280
- configureServer(r) {
281
- if (i && !m()) return;
282
- const y = W(n, o);
283
- if (!I(y)) return;
284
- r.watcher.add(y);
285
- const b = () => {
286
- u && clearTimeout(u), u = setTimeout(() => {
287
- i && g();
288
- const p = r.moduleGraph.getModuleById(w);
289
- p && (r.moduleGraph.invalidateModule(p), r.ws.send({ type: "full-reload" }));
290
- }, 50);
291
- };
292
- r.watcher.on("add", (p) => {
293
- p.startsWith(y) && p.endsWith(".json") && b();
294
- }), r.watcher.on("unlink", (p) => {
295
- p.startsWith(y) && p.endsWith(".json") && b();
296
- }), i && m() && r.watcher.on("change", (p) => {
297
- p.startsWith(y) && p.endsWith(".json") && b();
298
- });
299
- },
300
- resolveId(r) {
301
- if (r === V) return q;
302
- if (r === _) return w;
303
- },
304
- load(r) {
305
- if (r === q)
306
- return `export const config = ${JSON.stringify(l)}`;
307
- if (r === w)
308
- return i ? ie(h, f) : le(n, o, s);
309
- }
310
- };
262
+ function M(e, t) {
263
+ let n = e.defaultLocale || e.locale, r = e.translationDir ?? "locales", i = e.disablePageLocales === !0, o = {
264
+ defaultLocale: n,
265
+ fallbackLocale: e.fallbackLocale || n,
266
+ locales: e.locales || [],
267
+ localeCodes: (e.locales || []).map((e) => e.code),
268
+ missingWarn: e.missingWarn ?? !0,
269
+ syncWithVitePress: e.syncWithVitePress !== !1,
270
+ translationDir: r,
271
+ disablePageLocales: i,
272
+ localeKeyToCode: e.localeKeyToCode ?? {},
273
+ base: t && t !== "/" ? t : void 0
274
+ }, s = process.cwd(), c = !!(e.messages || e.routeMessages), l = e.messages ?? {}, u = e.routeMessages ?? {}, f, p = () => !e.messages || !e.routeMessages, m = () => {
275
+ if (!p()) return;
276
+ let t = w({
277
+ rootDir: s,
278
+ translationDir: r,
279
+ disablePageLocales: i
280
+ });
281
+ e.messages || (l = t.root), e.routeMessages || (u = t.routes);
282
+ };
283
+ return {
284
+ name: "vite-plugin-i18n-vitepress",
285
+ configResolved(t) {
286
+ s = t.root, c = !!(e.messages || e.routeMessages), c && (e.messages && (l = e.messages), e.routeMessages && (u = e.routeMessages), p() && m(), e.messages && (l = e.messages), e.routeMessages && (u = e.routeMessages));
287
+ },
288
+ configureServer(e) {
289
+ if (c && !p()) return;
290
+ let t = d(s, r);
291
+ if (!a(t)) return;
292
+ e.watcher.add(t);
293
+ let n = () => {
294
+ f && clearTimeout(f), f = setTimeout(() => {
295
+ c && m();
296
+ let t = e.moduleGraph.getModuleById(O);
297
+ t && (e.moduleGraph.invalidateModule(t), e.ws.send({ type: "full-reload" }));
298
+ }, 50);
299
+ };
300
+ e.watcher.on("add", (e) => {
301
+ e.startsWith(t) && e.endsWith(".json") && n();
302
+ }), e.watcher.on("unlink", (e) => {
303
+ e.startsWith(t) && e.endsWith(".json") && n();
304
+ }), c && p() && e.watcher.on("change", (e) => {
305
+ e.startsWith(t) && e.endsWith(".json") && n();
306
+ });
307
+ },
308
+ resolveId(e) {
309
+ if (e === T) return E;
310
+ if (e === D) return O;
311
+ },
312
+ load(e) {
313
+ if (e === E) return `export const config = ${JSON.stringify(o)}`;
314
+ if (e === O) return c ? j(l, u) : A(s, r, i);
315
+ }
316
+ };
311
317
  }
312
- function fe(e, t) {
313
- if (t.warnOnLocaleMismatch === !1) return;
314
- const a = e.locales;
315
- if (!a || !t.locales?.length) return;
316
- const o = t.defaultLocale || t.locale, s = Object.keys(a), l = new Set(t.locales.map((n) => n.code));
317
- for (const n of s) {
318
- const i = n === "root" ? o : t.localeKeyToCode?.[n] ?? n;
319
- l.has(i) || console.warn(
320
- `[i18n-micro/vitepress] VitePress locale key "${n}" maps to "${i}", which is not in i18n locales (${[...l].join(", ")}).`
321
- );
322
- }
318
+ function N(e, t) {
319
+ if (t.warnOnLocaleMismatch === !1) return;
320
+ let n = e.locales;
321
+ if (!n || !t.locales?.length) return;
322
+ let r = t.defaultLocale || t.locale, i = Object.keys(n), a = new Set(t.locales.map((e) => e.code));
323
+ for (let e of i) {
324
+ let n = e === "root" ? r : t.localeKeyToCode?.[e] ?? e;
325
+ a.has(n) || console.warn(`[i18n-micro/vitepress] VitePress locale key "${e}" maps to "${n}", which is not in i18n locales (${[...a].join(", ")}).`);
326
+ }
323
327
  }
324
- function be(e, t) {
325
- fe(e, t);
326
- const a = typeof e.base == "string" ? e.base : void 0, o = e.vite?.plugins, s = [...Array.isArray(o) ? o.flat() : [], ue(t, a)], l = e.vite?.ssr, n = l?.noExternal, i = [
327
- "@i18n-micro/vitepress",
328
- ...Array.isArray(n) ? n : n && n !== !0 ? [n] : []
329
- ], h = t.defaultLocale || t.locale, f = (t.locales || []).map((d) => d.code), u = e.themeConfig && typeof e.themeConfig == "object" ? e.themeConfig : {}, m = t.i18nRouting !== !1 && u.i18nRouting === void 0 && f.length > 0, g = t.meta ?? !!t.metaBaseUrl, r = t.locales || [], y = e.transformHead, b = e.transformPageData, p = g ? async (d) => {
330
- const x = typeof y == "function" ? await y(d) : [], v = Array.isArray(x) ? x : [];
331
- if (d.pageData?.frontmatter?.i18n?.disableMeta === !0) return v;
332
- const M = d.pageData?.relativePath || "index.md", T = (typeof e.base == "string" ? e.base : void 0) ?? d.siteData?.base ?? d.siteConfig?.site?.base, $ = E({
333
- path: R(M),
334
- locales: r,
335
- defaultLocale: h,
336
- localeKeyToCode: t.localeKeyToCode,
337
- base: T,
338
- metaBaseUrl: t.metaBaseUrl,
339
- hreflangBaseLanguage: t.hreflangBaseLanguage,
340
- canonicalQueryWhitelist: t.canonicalQueryWhitelist,
341
- missingWarn: t.missingWarn
342
- });
343
- return [...v, ...$.head];
344
- } : y, P = g ? async (d, x) => {
345
- if (typeof b == "function" && await b(d, x), d.frontmatter?.i18n?.disableMeta === !0) return;
346
- const v = E({
347
- path: R(d.relativePath || "index.md"),
348
- locales: r,
349
- defaultLocale: h,
350
- localeKeyToCode: t.localeKeyToCode,
351
- base: typeof e.base == "string" ? e.base : void 0,
352
- metaBaseUrl: t.metaBaseUrl,
353
- hreflangBaseLanguage: t.hreflangBaseLanguage,
354
- canonicalQueryWhitelist: t.canonicalQueryWhitelist,
355
- missingWarn: t.missingWarn,
356
- addSeoAttributes: !1
357
- });
358
- v.htmlAttrs.lang && (d.frontmatter ??= {}, d.frontmatter.lang || (d.frontmatter.lang = v.htmlAttrs.lang));
359
- } : b;
360
- return {
361
- ...e,
362
- ...m ? {
363
- themeConfig: {
364
- ...u,
365
- i18nRouting: U({
366
- defaultLocale: h,
367
- localeCodes: f,
368
- localeKeyToCode: t.localeKeyToCode,
369
- base: a
370
- })
371
- }
372
- } : {},
373
- ...g ? {
374
- transformHead: p,
375
- transformPageData: P
376
- } : {},
377
- vite: {
378
- ...e.vite,
379
- plugins: s,
380
- // Theme entry statically imports `virtual:i18n-micro/*`; Vite must bundle
381
- // the package during SSG so those IDs resolve (not left as bare Node imports).
382
- ssr: {
383
- ...l,
384
- noExternal: n === !0 ? !0 : i
385
- }
386
- }
387
- };
328
+ function P(e, t) {
329
+ N(e, t);
330
+ let n = typeof e.base == "string" ? e.base : void 0, r = e.vite?.plugins, i = [...Array.isArray(r) ? r.flat() : [], M(t, n)], a = e.vite?.ssr, o = a?.noExternal, s = ["@i18n-micro/vitepress", ...Array.isArray(o) ? o : o && o !== !0 ? [o] : []], c = t.defaultLocale || t.locale, l = (t.locales || []).map((e) => e.code), u = e.themeConfig && typeof e.themeConfig == "object" ? e.themeConfig : {}, d = t.i18nRouting !== !1 && u.i18nRouting === void 0 && l.length > 0, f = t.meta ?? !!t.metaBaseUrl, p = t.locales || [], m = e.transformHead, h = e.transformPageData, g = f ? async (n) => {
331
+ let r = typeof m == "function" ? await m(n) : [], i = Array.isArray(r) ? r : [];
332
+ if (n.pageData?.frontmatter?.i18n?.disableMeta === !0) return i;
333
+ let a = n.pageData?.relativePath || "index.md", o = (typeof e.base == "string" ? e.base : void 0) ?? n.siteData?.base ?? n.siteConfig?.site?.base, s = x({
334
+ path: b(a),
335
+ locales: p,
336
+ defaultLocale: c,
337
+ localeKeyToCode: t.localeKeyToCode,
338
+ base: o,
339
+ metaBaseUrl: t.metaBaseUrl,
340
+ hreflangBaseLanguage: t.hreflangBaseLanguage,
341
+ canonicalQueryWhitelist: t.canonicalQueryWhitelist,
342
+ missingWarn: t.missingWarn
343
+ });
344
+ return [...i, ...s.head];
345
+ } : m, v = f ? async (n, r) => {
346
+ if (typeof h == "function" && await h(n, r), n.frontmatter?.i18n?.disableMeta === !0) return;
347
+ let i = x({
348
+ path: b(n.relativePath || "index.md"),
349
+ locales: p,
350
+ defaultLocale: c,
351
+ localeKeyToCode: t.localeKeyToCode,
352
+ base: typeof e.base == "string" ? e.base : void 0,
353
+ metaBaseUrl: t.metaBaseUrl,
354
+ hreflangBaseLanguage: t.hreflangBaseLanguage,
355
+ canonicalQueryWhitelist: t.canonicalQueryWhitelist,
356
+ missingWarn: t.missingWarn,
357
+ addSeoAttributes: !1
358
+ });
359
+ i.htmlAttrs.lang && (n.frontmatter ??= {}, n.frontmatter.lang || (n.frontmatter.lang = i.htmlAttrs.lang));
360
+ } : h;
361
+ return {
362
+ ...e,
363
+ ...d ? { themeConfig: {
364
+ ...u,
365
+ i18nRouting: _({
366
+ defaultLocale: c,
367
+ localeCodes: l,
368
+ localeKeyToCode: t.localeKeyToCode,
369
+ base: n
370
+ })
371
+ } } : {},
372
+ ...f ? {
373
+ transformHead: g,
374
+ transformPageData: v
375
+ } : {},
376
+ vite: {
377
+ ...e.vite,
378
+ plugins: i,
379
+ ssr: {
380
+ ...a,
381
+ noExternal: o === !0 || s
382
+ }
383
+ }
384
+ };
388
385
  }
389
- export {
390
- E as buildVitePressLocaleHead,
391
- ve as buildVitePressLocales,
392
- R as relativePathToRoutePath,
393
- fe as warnLocaleMismatch,
394
- be as withI18n
395
- };
396
- //# sourceMappingURL=config.mjs.map
386
+ //#endregion
387
+ export { x as buildVitePressLocaleHead, n as buildVitePressLocales, b as relativePathToRoutePath, N as warnLocaleMismatch, P as withI18n };
388
+
389
+ //# sourceMappingURL=config.mjs.map