@i18n-micro/vitepress 1.0.1 → 1.1.0
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/README.md +73 -39
- package/client.d.ts +1 -0
- package/dist/adapter-BJ-0ltIc.cjs +2 -0
- package/dist/adapter-BJ-0ltIc.cjs.map +1 -0
- package/dist/adapter-BnsyIKhp.js +128 -0
- package/dist/adapter-BnsyIKhp.js.map +1 -0
- package/dist/config.cjs +64 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +113 -111
- package/dist/config.d.ts +113 -111
- package/dist/config.mjs +393 -9
- package/dist/config.mjs.map +1 -1
- package/dist/create-BgMbe0w1.cjs +2 -0
- package/dist/create-BgMbe0w1.cjs.map +1 -0
- package/dist/create-Dev8Q66O.js +80 -0
- package/dist/create-Dev8Q66O.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -141
- package/dist/index.d.ts +87 -141
- package/dist/index.mjs +28 -249
- package/dist/index.mjs.map +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +56 -116
- package/dist/node.d.ts +56 -116
- package/dist/node.mjs +23 -7
- package/dist/node.mjs.map +1 -1
- package/dist/{virtual-stubs → plugin/virtual-stubs}/config.d.cts +2 -1
- package/dist/runtime/define-theme.d.cts +39 -0
- package/dist/theme.cjs +2 -0
- package/dist/theme.cjs.map +1 -0
- package/dist/theme.d.cts +58 -0
- package/dist/theme.d.ts +58 -0
- package/dist/theme.mjs +35 -0
- package/dist/theme.mjs.map +1 -0
- package/dist/vitepress-locales-6msv22Sn.js +27 -0
- package/dist/vitepress-locales-6msv22Sn.js.map +1 -0
- package/dist/vitepress-locales-Cz4AutfI.cjs +2 -0
- package/dist/vitepress-locales-Cz4AutfI.cjs.map +1 -0
- package/package.json +18 -6
- package/dist/i18n-routing-CcppCuuS.js +0 -64
- package/dist/i18n-routing-CcppCuuS.js.map +0 -1
- package/dist/i18n-routing-D9iYAKDq.cjs +0 -46
- package/dist/i18n-routing-D9iYAKDq.cjs.map +0 -1
- package/dist/with-i18n-micro-01q-vPO9.cjs +0 -15
- package/dist/with-i18n-micro-01q-vPO9.cjs.map +0 -1
- package/dist/with-i18n-micro-DIAoqY71.js +0 -216
- package/dist/with-i18n-micro-DIAoqY71.js.map +0 -1
package/dist/config.d.cts
CHANGED
|
@@ -1,88 +1,62 @@
|
|
|
1
|
-
import { I18nRoutingStrategy } from '@i18n-micro/vue';
|
|
2
1
|
import { Locale } from '@i18n-micro/types';
|
|
3
2
|
import { Plugin as Plugin_2 } from 'vite';
|
|
4
3
|
import { PluralFunc } from '@i18n-micro/types';
|
|
5
|
-
import { TranslationFileBuckets } from '@i18n-micro/utils/parse-path';
|
|
6
4
|
import { Translations } from '@i18n-micro/types';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
export declare function applyLoadedTranslations(i18n: {
|
|
12
|
-
addTranslations: (locale: string, translations: Translations, merge?: boolean) => void;
|
|
13
|
-
addRouteTranslations: (locale: string, routeName: string, translations: Translations, merge?: boolean) => void;
|
|
14
|
-
}, loaded: LoadedTranslations): void;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Bridge so VitePress navbar language menu and `<I18nSwitcher>` share path logic.
|
|
18
|
-
* Pass the result to `themeConfig.i18nRouting`.
|
|
7
|
+
* Build i18n SEO head for VitePress — same tags as Nuxt `useLocaleHead` /
|
|
8
|
+
* plugin `02.meta` (canonical, hreflang, x-default, og:locale / og:url / alternates).
|
|
19
9
|
*
|
|
20
|
-
*
|
|
21
|
-
* `localeKeyToCode` is only for resolving the i18n code when callers need it elsewhere.
|
|
22
|
-
*
|
|
23
|
-
* Returns a **self-contained** function (no closures) so VitePress can serialize it
|
|
24
|
-
* into site data via `Function#toString()` + `new Function`.
|
|
10
|
+
* Framework-agnostic pure function; wired automatically by `withI18n` when `meta` is on.
|
|
25
11
|
*/
|
|
26
|
-
export declare function
|
|
12
|
+
export declare function buildVitePressLocaleHead(options: BuildVitePressLocaleHeadOptions): VitePressLocaleHeadObject;
|
|
27
13
|
|
|
28
|
-
export declare interface
|
|
14
|
+
export declare interface BuildVitePressLocaleHeadOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Current page path (with or without `site.base`). Query/hash optional.
|
|
17
|
+
* Example: `/docs/fr/guide/` or `/fr/guide`.
|
|
18
|
+
*/
|
|
19
|
+
path: string;
|
|
20
|
+
locales: Locale[];
|
|
29
21
|
defaultLocale: string;
|
|
30
|
-
localeCodes: string[];
|
|
31
22
|
localeKeyToCode?: Record<string, string>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* List JSON translation files under `translationDir` (absolute + relative paths).
|
|
36
|
-
*/
|
|
37
|
-
export declare function listTranslationFiles(options: LoadMessagesOptions): TranslationFileRef[];
|
|
38
|
-
|
|
39
|
-
export declare type LoadedTranslations = TranslationFileBuckets<Translations>;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Load root-level locale JSON only (`en.json`, `fr.json`, …).
|
|
43
|
-
* Prefer `loadTranslationBuckets` when page locales are needed.
|
|
44
|
-
*
|
|
45
|
-
* Node.js-only (`node:fs`). For bundler-friendly loading prefer
|
|
46
|
-
* `withI18nMicro` virtual modules or `messagesFromGlob` in the theme.
|
|
47
|
-
*/
|
|
48
|
-
export declare function loadMessages(options: LoadMessagesOptions): Record<string, Translations>;
|
|
49
|
-
|
|
50
|
-
export declare interface LoadMessagesOptions {
|
|
51
|
-
/** Directory with locale JSON (`en.json`, `pages/guide/demo/en.json`, …). */
|
|
52
|
-
translationDir: string;
|
|
53
|
-
rootDir?: string;
|
|
23
|
+
/** VitePress `site.base` (e.g. `/docs/`). */
|
|
24
|
+
base?: string;
|
|
54
25
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
26
|
+
* Public site origin **without** trailing slash (e.g. `https://example.com`).
|
|
27
|
+
* Required for absolute `canonical` / `hreflang` / `og:url`.
|
|
28
|
+
* When omitted, only `htmlAttrs` are produced.
|
|
57
29
|
*/
|
|
58
|
-
|
|
30
|
+
metaBaseUrl?: string;
|
|
31
|
+
/** @default false — same as Nuxt / Vue `useLocaleHead`. */
|
|
32
|
+
hreflangBaseLanguage?: boolean;
|
|
33
|
+
/** Query keys kept on canonical / alternate URLs. @default [] */
|
|
34
|
+
canonicalQueryWhitelist?: string[];
|
|
35
|
+
/** @default true */
|
|
36
|
+
addDirAttribute?: boolean;
|
|
37
|
+
/** @default true */
|
|
38
|
+
addSeoAttributes?: boolean;
|
|
39
|
+
/** @default 'id' */
|
|
40
|
+
identifierAttribute?: string;
|
|
41
|
+
missingWarn?: boolean;
|
|
59
42
|
}
|
|
60
43
|
|
|
61
44
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
45
|
+
* Build VitePress `config.locales` from i18n-micro `Locale[]`.
|
|
46
|
+
* Default locale becomes `root` (no URL prefix); others get `/{key}/`.
|
|
64
47
|
*/
|
|
65
|
-
export declare function
|
|
48
|
+
export declare function buildVitePressLocales(locales: Locale[], defaultLocale: string, options?: BuildVitePressLocalesOptions): Record<string, VitePressLocaleEntry>;
|
|
66
49
|
|
|
67
|
-
export declare interface
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
defaultLocale: string;
|
|
75
|
-
fallbackLocale: string;
|
|
76
|
-
locales: Locale[];
|
|
77
|
-
localeCodes: string[];
|
|
78
|
-
missingWarn: boolean;
|
|
79
|
-
syncWithVitePress: boolean;
|
|
80
|
-
translationDir: string;
|
|
81
|
-
disablePageLocales: boolean;
|
|
82
|
-
localeKeyToCode: Record<string, string>;
|
|
50
|
+
export declare interface BuildVitePressLocalesOptions {
|
|
51
|
+
/**
|
|
52
|
+
* Map VitePress locale keys → i18n codes (`root` → default).
|
|
53
|
+
* When a non-default code maps to a short VP key (`fr` → `fr-FR`), the URL
|
|
54
|
+
* prefix / config key uses the VP key.
|
|
55
|
+
*/
|
|
56
|
+
localeKeyToCode?: Record<string, string>;
|
|
83
57
|
}
|
|
84
58
|
|
|
85
|
-
declare interface
|
|
59
|
+
declare interface CreateI18nOptions {
|
|
86
60
|
locale: string;
|
|
87
61
|
fallbackLocale?: string;
|
|
88
62
|
locales?: Locale[];
|
|
@@ -90,7 +64,7 @@ declare interface VitePressI18nOptions {
|
|
|
90
64
|
messages?: Record<string, Translations>;
|
|
91
65
|
/**
|
|
92
66
|
* Page-scoped dictionaries keyed by route name (`guide-demo`), then locale.
|
|
93
|
-
* Loaded from `locales/pages/**` when using `
|
|
67
|
+
* Loaded from `locales/pages/**` when using `withI18n`.
|
|
94
68
|
*/
|
|
95
69
|
routeMessages?: Record<string, Record<string, Translations>>;
|
|
96
70
|
plural?: PluralFunc;
|
|
@@ -105,52 +79,51 @@ declare interface VitePressI18nOptions {
|
|
|
105
79
|
* Map VitePress locale keys to i18n codes (`root` → default locale code).
|
|
106
80
|
*/
|
|
107
81
|
localeKeyToCode?: Record<string, string>;
|
|
82
|
+
/**
|
|
83
|
+
* VitePress `site.base`. Needed so SSG paths (`withBase`) and lang switcher
|
|
84
|
+
* do not treat the base segment as content / double-prefix links.
|
|
85
|
+
*/
|
|
86
|
+
base?: string;
|
|
108
87
|
}
|
|
109
88
|
|
|
110
89
|
/**
|
|
111
|
-
*
|
|
112
|
-
* Kept loose so we do not hard-depend on VitePress internal DefaultTheme types at compile time.
|
|
90
|
+
* Convert VitePress `pageData.relativePath` to a route path (cleanUrls-style).
|
|
113
91
|
*/
|
|
114
|
-
export declare
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
92
|
+
export declare function relativePathToRoutePath(relativePath: string): string;
|
|
93
|
+
|
|
94
|
+
export declare interface VirtualI18nConfig {
|
|
95
|
+
defaultLocale: string;
|
|
96
|
+
fallbackLocale: string;
|
|
97
|
+
locales: Locale[];
|
|
98
|
+
localeCodes: string[];
|
|
99
|
+
missingWarn: boolean;
|
|
100
|
+
syncWithVitePress: boolean;
|
|
101
|
+
translationDir: string;
|
|
102
|
+
disablePageLocales: boolean;
|
|
103
|
+
localeKeyToCode: Record<string, string>;
|
|
104
|
+
/** VitePress `site.base` (normalized, trailing slash preserved from config). */
|
|
105
|
+
base?: string;
|
|
126
106
|
}
|
|
127
107
|
|
|
128
|
-
|
|
108
|
+
/** VitePress `HeadConfig` tuple (tag + attrs). */
|
|
109
|
+
export declare type VitePressHeadTuple = [string, Record<string, string>];
|
|
129
110
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Minimal VitePress `locales` entry used by the default theme language menu.
|
|
113
|
+
*/
|
|
114
|
+
export declare interface VitePressLocaleEntry {
|
|
115
|
+
label: string;
|
|
116
|
+
lang: string;
|
|
117
|
+
link?: string;
|
|
137
118
|
}
|
|
138
119
|
|
|
139
|
-
declare interface
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
|
|
146
|
-
/** Resolve i18n code to VitePress locale key. */
|
|
147
|
-
localeKeyFromCode: (code: string) => string;
|
|
148
|
-
localeCodes: string[];
|
|
149
|
-
defaultLocale: string;
|
|
150
|
-
/** Snapshot of mapping used when building the adapter (for `i18nRouting` serialization). */
|
|
151
|
-
localeKeyToCode: Record<string, string>;
|
|
152
|
-
/** URL path prefixes (VitePress locale keys except `root`). */
|
|
153
|
-
urlPrefixes: string[];
|
|
120
|
+
export declare interface VitePressLocaleHeadObject {
|
|
121
|
+
htmlAttrs: {
|
|
122
|
+
lang?: string;
|
|
123
|
+
dir?: 'ltr' | 'rtl' | 'auto';
|
|
124
|
+
};
|
|
125
|
+
/** Ready for `transformHead` / `frontmatter.head`. */
|
|
126
|
+
head: VitePressHeadTuple[];
|
|
154
127
|
}
|
|
155
128
|
|
|
156
129
|
/**
|
|
@@ -158,31 +131,38 @@ declare interface VitePressRouterAdapter extends I18nRoutingStrategy {
|
|
|
158
131
|
* Avoid importing `vitepress` types so the package stays usable as a pure library dep.
|
|
159
132
|
*/
|
|
160
133
|
export declare interface VitePressUserConfigLike {
|
|
134
|
+
base?: string;
|
|
161
135
|
locales?: Record<string, unknown>;
|
|
136
|
+
themeConfig?: Record<string, unknown> | null;
|
|
137
|
+
transformHead?: (...args: any[]) => any;
|
|
138
|
+
transformPageData?: (...args: any[]) => any;
|
|
162
139
|
vite?: {
|
|
163
140
|
plugins?: Plugin_2[] | Plugin_2[][];
|
|
141
|
+
ssr?: {
|
|
142
|
+
noExternal?: string | true | Array<string | RegExp>;
|
|
143
|
+
[key: string]: unknown;
|
|
144
|
+
};
|
|
164
145
|
[key: string]: unknown;
|
|
165
146
|
};
|
|
166
147
|
[key: string]: unknown;
|
|
167
148
|
}
|
|
168
149
|
|
|
169
|
-
export declare function warnLocaleMismatch(config: VitePressUserConfigLike, options:
|
|
150
|
+
export declare function warnLocaleMismatch(config: VitePressUserConfigLike, options: WithI18nOptions): void;
|
|
170
151
|
|
|
171
152
|
/**
|
|
172
|
-
*
|
|
173
|
-
* `withI18n` is already used by the unrelated `vitepress-i18n` package.
|
|
153
|
+
* VitePress config helper: virtual modules + optional `i18nRouting` / SEO head.
|
|
174
154
|
*
|
|
175
|
-
* Registers
|
|
155
|
+
* Registers:
|
|
176
156
|
* - `virtual:i18n-micro/config`
|
|
177
157
|
* - `virtual:i18n-micro/messages` (from `translationDir`, default `locales/`)
|
|
178
158
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
159
|
+
* By default also sets `themeConfig.i18nRouting` (pass `i18nRouting: false` to skip).
|
|
160
|
+
* Pair with `defineI18nTheme(DefaultTheme)` from `@i18n-micro/vitepress/theme`.
|
|
181
161
|
* Import from `@i18n-micro/vitepress/config` (Node / config files only).
|
|
182
162
|
*/
|
|
183
|
-
export declare function
|
|
163
|
+
export declare function withI18n<T extends VitePressUserConfigLike>(config: T, options: WithI18nOptions): T;
|
|
184
164
|
|
|
185
|
-
export declare interface
|
|
165
|
+
export declare interface WithI18nOptions extends CreateI18nOptions {
|
|
186
166
|
/**
|
|
187
167
|
* Directory with locale JSON (`en.json`, `pages/guide/demo/en.json`, …), relative to Vite root
|
|
188
168
|
* (VitePress content / docs root). Used by `virtual:i18n-micro/messages`.
|
|
@@ -200,6 +180,28 @@ export declare interface WithI18nMicroOptions extends VitePressI18nOptions {
|
|
|
200
180
|
* @default true
|
|
201
181
|
*/
|
|
202
182
|
warnOnLocaleMismatch?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Inject `themeConfig.i18nRouting` from adapter options + `config.base`.
|
|
185
|
+
* Set `false` to skip. Skipped automatically when `themeConfig.i18nRouting` is already set.
|
|
186
|
+
* @default true
|
|
187
|
+
*/
|
|
188
|
+
i18nRouting?: boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Emit i18n SEO tags via `transformHead` (canonical, hreflang, og:locale…) —
|
|
191
|
+
* Nuxt `meta` / plugin `02.meta` analogue.
|
|
192
|
+
* Absolute link tags require `metaBaseUrl`.
|
|
193
|
+
* @default true when `metaBaseUrl` is set, otherwise false
|
|
194
|
+
*/
|
|
195
|
+
meta?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Public origin without trailing slash (`https://example.com`).
|
|
198
|
+
* Same role as Nuxt `metaBaseUrl`.
|
|
199
|
+
*/
|
|
200
|
+
metaBaseUrl?: string;
|
|
201
|
+
/** Also emit bare-language hreflang from `iso` (Nuxt `hreflangBaseLanguage`). @default false */
|
|
202
|
+
hreflangBaseLanguage?: boolean;
|
|
203
|
+
/** Query keys kept on canonical / alternate URLs. @default [] */
|
|
204
|
+
canonicalQueryWhitelist?: string[];
|
|
203
205
|
}
|
|
204
206
|
|
|
205
207
|
export { }
|
package/dist/config.d.ts
CHANGED
|
@@ -1,88 +1,62 @@
|
|
|
1
|
-
import { I18nRoutingStrategy } from '@i18n-micro/vue';
|
|
2
1
|
import { Locale } from '@i18n-micro/types';
|
|
3
2
|
import { Plugin as Plugin_2 } from 'vite';
|
|
4
3
|
import { PluralFunc } from '@i18n-micro/types';
|
|
5
|
-
import { TranslationFileBuckets } from '@i18n-micro/utils/parse-path';
|
|
6
4
|
import { Translations } from '@i18n-micro/types';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
export declare function applyLoadedTranslations(i18n: {
|
|
12
|
-
addTranslations: (locale: string, translations: Translations, merge?: boolean) => void;
|
|
13
|
-
addRouteTranslations: (locale: string, routeName: string, translations: Translations, merge?: boolean) => void;
|
|
14
|
-
}, loaded: LoadedTranslations): void;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Bridge so VitePress navbar language menu and `<I18nSwitcher>` share path logic.
|
|
18
|
-
* Pass the result to `themeConfig.i18nRouting`.
|
|
7
|
+
* Build i18n SEO head for VitePress — same tags as Nuxt `useLocaleHead` /
|
|
8
|
+
* plugin `02.meta` (canonical, hreflang, x-default, og:locale / og:url / alternates).
|
|
19
9
|
*
|
|
20
|
-
*
|
|
21
|
-
* `localeKeyToCode` is only for resolving the i18n code when callers need it elsewhere.
|
|
22
|
-
*
|
|
23
|
-
* Returns a **self-contained** function (no closures) so VitePress can serialize it
|
|
24
|
-
* into site data via `Function#toString()` + `new Function`.
|
|
10
|
+
* Framework-agnostic pure function; wired automatically by `withI18n` when `meta` is on.
|
|
25
11
|
*/
|
|
26
|
-
export declare function
|
|
12
|
+
export declare function buildVitePressLocaleHead(options: BuildVitePressLocaleHeadOptions): VitePressLocaleHeadObject;
|
|
27
13
|
|
|
28
|
-
export declare interface
|
|
14
|
+
export declare interface BuildVitePressLocaleHeadOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Current page path (with or without `site.base`). Query/hash optional.
|
|
17
|
+
* Example: `/docs/fr/guide/` or `/fr/guide`.
|
|
18
|
+
*/
|
|
19
|
+
path: string;
|
|
20
|
+
locales: Locale[];
|
|
29
21
|
defaultLocale: string;
|
|
30
|
-
localeCodes: string[];
|
|
31
22
|
localeKeyToCode?: Record<string, string>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* List JSON translation files under `translationDir` (absolute + relative paths).
|
|
36
|
-
*/
|
|
37
|
-
export declare function listTranslationFiles(options: LoadMessagesOptions): TranslationFileRef[];
|
|
38
|
-
|
|
39
|
-
export declare type LoadedTranslations = TranslationFileBuckets<Translations>;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Load root-level locale JSON only (`en.json`, `fr.json`, …).
|
|
43
|
-
* Prefer `loadTranslationBuckets` when page locales are needed.
|
|
44
|
-
*
|
|
45
|
-
* Node.js-only (`node:fs`). For bundler-friendly loading prefer
|
|
46
|
-
* `withI18nMicro` virtual modules or `messagesFromGlob` in the theme.
|
|
47
|
-
*/
|
|
48
|
-
export declare function loadMessages(options: LoadMessagesOptions): Record<string, Translations>;
|
|
49
|
-
|
|
50
|
-
export declare interface LoadMessagesOptions {
|
|
51
|
-
/** Directory with locale JSON (`en.json`, `pages/guide/demo/en.json`, …). */
|
|
52
|
-
translationDir: string;
|
|
53
|
-
rootDir?: string;
|
|
23
|
+
/** VitePress `site.base` (e.g. `/docs/`). */
|
|
24
|
+
base?: string;
|
|
54
25
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
26
|
+
* Public site origin **without** trailing slash (e.g. `https://example.com`).
|
|
27
|
+
* Required for absolute `canonical` / `hreflang` / `og:url`.
|
|
28
|
+
* When omitted, only `htmlAttrs` are produced.
|
|
57
29
|
*/
|
|
58
|
-
|
|
30
|
+
metaBaseUrl?: string;
|
|
31
|
+
/** @default false — same as Nuxt / Vue `useLocaleHead`. */
|
|
32
|
+
hreflangBaseLanguage?: boolean;
|
|
33
|
+
/** Query keys kept on canonical / alternate URLs. @default [] */
|
|
34
|
+
canonicalQueryWhitelist?: string[];
|
|
35
|
+
/** @default true */
|
|
36
|
+
addDirAttribute?: boolean;
|
|
37
|
+
/** @default true */
|
|
38
|
+
addSeoAttributes?: boolean;
|
|
39
|
+
/** @default 'id' */
|
|
40
|
+
identifierAttribute?: string;
|
|
41
|
+
missingWarn?: boolean;
|
|
59
42
|
}
|
|
60
43
|
|
|
61
44
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
45
|
+
* Build VitePress `config.locales` from i18n-micro `Locale[]`.
|
|
46
|
+
* Default locale becomes `root` (no URL prefix); others get `/{key}/`.
|
|
64
47
|
*/
|
|
65
|
-
export declare function
|
|
48
|
+
export declare function buildVitePressLocales(locales: Locale[], defaultLocale: string, options?: BuildVitePressLocalesOptions): Record<string, VitePressLocaleEntry>;
|
|
66
49
|
|
|
67
|
-
export declare interface
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
defaultLocale: string;
|
|
75
|
-
fallbackLocale: string;
|
|
76
|
-
locales: Locale[];
|
|
77
|
-
localeCodes: string[];
|
|
78
|
-
missingWarn: boolean;
|
|
79
|
-
syncWithVitePress: boolean;
|
|
80
|
-
translationDir: string;
|
|
81
|
-
disablePageLocales: boolean;
|
|
82
|
-
localeKeyToCode: Record<string, string>;
|
|
50
|
+
export declare interface BuildVitePressLocalesOptions {
|
|
51
|
+
/**
|
|
52
|
+
* Map VitePress locale keys → i18n codes (`root` → default).
|
|
53
|
+
* When a non-default code maps to a short VP key (`fr` → `fr-FR`), the URL
|
|
54
|
+
* prefix / config key uses the VP key.
|
|
55
|
+
*/
|
|
56
|
+
localeKeyToCode?: Record<string, string>;
|
|
83
57
|
}
|
|
84
58
|
|
|
85
|
-
declare interface
|
|
59
|
+
declare interface CreateI18nOptions {
|
|
86
60
|
locale: string;
|
|
87
61
|
fallbackLocale?: string;
|
|
88
62
|
locales?: Locale[];
|
|
@@ -90,7 +64,7 @@ declare interface VitePressI18nOptions {
|
|
|
90
64
|
messages?: Record<string, Translations>;
|
|
91
65
|
/**
|
|
92
66
|
* Page-scoped dictionaries keyed by route name (`guide-demo`), then locale.
|
|
93
|
-
* Loaded from `locales/pages/**` when using `
|
|
67
|
+
* Loaded from `locales/pages/**` when using `withI18n`.
|
|
94
68
|
*/
|
|
95
69
|
routeMessages?: Record<string, Record<string, Translations>>;
|
|
96
70
|
plural?: PluralFunc;
|
|
@@ -105,52 +79,51 @@ declare interface VitePressI18nOptions {
|
|
|
105
79
|
* Map VitePress locale keys to i18n codes (`root` → default locale code).
|
|
106
80
|
*/
|
|
107
81
|
localeKeyToCode?: Record<string, string>;
|
|
82
|
+
/**
|
|
83
|
+
* VitePress `site.base`. Needed so SSG paths (`withBase`) and lang switcher
|
|
84
|
+
* do not treat the base segment as content / double-prefix links.
|
|
85
|
+
*/
|
|
86
|
+
base?: string;
|
|
108
87
|
}
|
|
109
88
|
|
|
110
89
|
/**
|
|
111
|
-
*
|
|
112
|
-
* Kept loose so we do not hard-depend on VitePress internal DefaultTheme types at compile time.
|
|
90
|
+
* Convert VitePress `pageData.relativePath` to a route path (cleanUrls-style).
|
|
113
91
|
*/
|
|
114
|
-
export declare
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
92
|
+
export declare function relativePathToRoutePath(relativePath: string): string;
|
|
93
|
+
|
|
94
|
+
export declare interface VirtualI18nConfig {
|
|
95
|
+
defaultLocale: string;
|
|
96
|
+
fallbackLocale: string;
|
|
97
|
+
locales: Locale[];
|
|
98
|
+
localeCodes: string[];
|
|
99
|
+
missingWarn: boolean;
|
|
100
|
+
syncWithVitePress: boolean;
|
|
101
|
+
translationDir: string;
|
|
102
|
+
disablePageLocales: boolean;
|
|
103
|
+
localeKeyToCode: Record<string, string>;
|
|
104
|
+
/** VitePress `site.base` (normalized, trailing slash preserved from config). */
|
|
105
|
+
base?: string;
|
|
126
106
|
}
|
|
127
107
|
|
|
128
|
-
|
|
108
|
+
/** VitePress `HeadConfig` tuple (tag + attrs). */
|
|
109
|
+
export declare type VitePressHeadTuple = [string, Record<string, string>];
|
|
129
110
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Minimal VitePress `locales` entry used by the default theme language menu.
|
|
113
|
+
*/
|
|
114
|
+
export declare interface VitePressLocaleEntry {
|
|
115
|
+
label: string;
|
|
116
|
+
lang: string;
|
|
117
|
+
link?: string;
|
|
137
118
|
}
|
|
138
119
|
|
|
139
|
-
declare interface
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
|
|
146
|
-
/** Resolve i18n code to VitePress locale key. */
|
|
147
|
-
localeKeyFromCode: (code: string) => string;
|
|
148
|
-
localeCodes: string[];
|
|
149
|
-
defaultLocale: string;
|
|
150
|
-
/** Snapshot of mapping used when building the adapter (for `i18nRouting` serialization). */
|
|
151
|
-
localeKeyToCode: Record<string, string>;
|
|
152
|
-
/** URL path prefixes (VitePress locale keys except `root`). */
|
|
153
|
-
urlPrefixes: string[];
|
|
120
|
+
export declare interface VitePressLocaleHeadObject {
|
|
121
|
+
htmlAttrs: {
|
|
122
|
+
lang?: string;
|
|
123
|
+
dir?: 'ltr' | 'rtl' | 'auto';
|
|
124
|
+
};
|
|
125
|
+
/** Ready for `transformHead` / `frontmatter.head`. */
|
|
126
|
+
head: VitePressHeadTuple[];
|
|
154
127
|
}
|
|
155
128
|
|
|
156
129
|
/**
|
|
@@ -158,31 +131,38 @@ declare interface VitePressRouterAdapter extends I18nRoutingStrategy {
|
|
|
158
131
|
* Avoid importing `vitepress` types so the package stays usable as a pure library dep.
|
|
159
132
|
*/
|
|
160
133
|
export declare interface VitePressUserConfigLike {
|
|
134
|
+
base?: string;
|
|
161
135
|
locales?: Record<string, unknown>;
|
|
136
|
+
themeConfig?: Record<string, unknown> | null;
|
|
137
|
+
transformHead?: (...args: any[]) => any;
|
|
138
|
+
transformPageData?: (...args: any[]) => any;
|
|
162
139
|
vite?: {
|
|
163
140
|
plugins?: Plugin_2[] | Plugin_2[][];
|
|
141
|
+
ssr?: {
|
|
142
|
+
noExternal?: string | true | Array<string | RegExp>;
|
|
143
|
+
[key: string]: unknown;
|
|
144
|
+
};
|
|
164
145
|
[key: string]: unknown;
|
|
165
146
|
};
|
|
166
147
|
[key: string]: unknown;
|
|
167
148
|
}
|
|
168
149
|
|
|
169
|
-
export declare function warnLocaleMismatch(config: VitePressUserConfigLike, options:
|
|
150
|
+
export declare function warnLocaleMismatch(config: VitePressUserConfigLike, options: WithI18nOptions): void;
|
|
170
151
|
|
|
171
152
|
/**
|
|
172
|
-
*
|
|
173
|
-
* `withI18n` is already used by the unrelated `vitepress-i18n` package.
|
|
153
|
+
* VitePress config helper: virtual modules + optional `i18nRouting` / SEO head.
|
|
174
154
|
*
|
|
175
|
-
* Registers
|
|
155
|
+
* Registers:
|
|
176
156
|
* - `virtual:i18n-micro/config`
|
|
177
157
|
* - `virtual:i18n-micro/messages` (from `translationDir`, default `locales/`)
|
|
178
158
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
159
|
+
* By default also sets `themeConfig.i18nRouting` (pass `i18nRouting: false` to skip).
|
|
160
|
+
* Pair with `defineI18nTheme(DefaultTheme)` from `@i18n-micro/vitepress/theme`.
|
|
181
161
|
* Import from `@i18n-micro/vitepress/config` (Node / config files only).
|
|
182
162
|
*/
|
|
183
|
-
export declare function
|
|
163
|
+
export declare function withI18n<T extends VitePressUserConfigLike>(config: T, options: WithI18nOptions): T;
|
|
184
164
|
|
|
185
|
-
export declare interface
|
|
165
|
+
export declare interface WithI18nOptions extends CreateI18nOptions {
|
|
186
166
|
/**
|
|
187
167
|
* Directory with locale JSON (`en.json`, `pages/guide/demo/en.json`, …), relative to Vite root
|
|
188
168
|
* (VitePress content / docs root). Used by `virtual:i18n-micro/messages`.
|
|
@@ -200,6 +180,28 @@ export declare interface WithI18nMicroOptions extends VitePressI18nOptions {
|
|
|
200
180
|
* @default true
|
|
201
181
|
*/
|
|
202
182
|
warnOnLocaleMismatch?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Inject `themeConfig.i18nRouting` from adapter options + `config.base`.
|
|
185
|
+
* Set `false` to skip. Skipped automatically when `themeConfig.i18nRouting` is already set.
|
|
186
|
+
* @default true
|
|
187
|
+
*/
|
|
188
|
+
i18nRouting?: boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Emit i18n SEO tags via `transformHead` (canonical, hreflang, og:locale…) —
|
|
191
|
+
* Nuxt `meta` / plugin `02.meta` analogue.
|
|
192
|
+
* Absolute link tags require `metaBaseUrl`.
|
|
193
|
+
* @default true when `metaBaseUrl` is set, otherwise false
|
|
194
|
+
*/
|
|
195
|
+
meta?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Public origin without trailing slash (`https://example.com`).
|
|
198
|
+
* Same role as Nuxt `metaBaseUrl`.
|
|
199
|
+
*/
|
|
200
|
+
metaBaseUrl?: string;
|
|
201
|
+
/** Also emit bare-language hreflang from `iso` (Nuxt `hreflangBaseLanguage`). @default false */
|
|
202
|
+
hreflangBaseLanguage?: boolean;
|
|
203
|
+
/** Query keys kept on canonical / alternate URLs. @default [] */
|
|
204
|
+
canonicalQueryWhitelist?: string[];
|
|
203
205
|
}
|
|
204
206
|
|
|
205
207
|
export { }
|