@vuepress/shared 2.0.0-rc.30 → 2.0.0-rc.32
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/index.d.ts +21 -66
- package/dist/index.js +17 -34
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { MarkdownItHeader } from "@mdit-vue/types";
|
|
2
|
-
|
|
3
|
-
//#region src/types/head.d.ts
|
|
4
2
|
/**
|
|
5
3
|
* Config for `<head>` tags
|
|
6
4
|
*/
|
|
@@ -23,8 +21,6 @@ type HeadTagEmpty = 'base' | 'link' | 'meta' | 'script';
|
|
|
23
21
|
* Attributes to be set for tags in `<head>`
|
|
24
22
|
*/
|
|
25
23
|
type HeadAttrsConfig = Record<string, boolean | string>;
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/types/locale.d.ts
|
|
28
24
|
/**
|
|
29
25
|
* Locales config, a key-value object
|
|
30
26
|
*
|
|
@@ -37,9 +33,7 @@ type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>
|
|
|
37
33
|
/**
|
|
38
34
|
* Locales data
|
|
39
35
|
*/
|
|
40
|
-
type LocaleData =
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/types/page.d.ts
|
|
36
|
+
type LocaleData = object;
|
|
43
37
|
/**
|
|
44
38
|
* Base type of vuepress page
|
|
45
39
|
*/
|
|
@@ -93,8 +87,6 @@ type PageFrontmatter<T extends Record<string, unknown> = Record<string, unknown>
|
|
|
93
87
|
* Vuepress page header
|
|
94
88
|
*/
|
|
95
89
|
type PageHeader = MarkdownItHeader;
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region src/types/site.d.ts
|
|
98
90
|
/**
|
|
99
91
|
* Vuepress site data
|
|
100
92
|
*/
|
|
@@ -172,8 +164,6 @@ interface SiteLocaleData {
|
|
|
172
164
|
* Site locale config
|
|
173
165
|
*/
|
|
174
166
|
type SiteLocaleConfig = LocaleConfig<SiteLocaleData>;
|
|
175
|
-
//#endregion
|
|
176
|
-
//#region src/types/ssr.d.ts
|
|
177
167
|
/**
|
|
178
168
|
* Context for SSR
|
|
179
169
|
*/
|
|
@@ -181,14 +171,10 @@ interface VuepressSSRContext {
|
|
|
181
171
|
lang: string;
|
|
182
172
|
head: HeadConfig[];
|
|
183
173
|
}
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region src/utils/links/isLinkExternal.d.ts
|
|
186
174
|
/**
|
|
187
175
|
* Determine a link is external or not
|
|
188
176
|
*/
|
|
189
|
-
declare const isLinkExternal: (link: string, base?: string) => boolean;
|
|
190
|
-
//#endregion
|
|
191
|
-
//#region src/utils/links/isLinkHttp.d.ts
|
|
177
|
+
export declare const isLinkExternal: (link: string, base?: string) => boolean;
|
|
192
178
|
/**
|
|
193
179
|
* Determine a link is http link or not
|
|
194
180
|
*
|
|
@@ -196,109 +182,78 @@ declare const isLinkExternal: (link: string, base?: string) => boolean;
|
|
|
196
182
|
* - https://github.com
|
|
197
183
|
* - //github.com
|
|
198
184
|
*/
|
|
199
|
-
declare const isLinkHttp: (link: string) => boolean;
|
|
200
|
-
//#endregion
|
|
201
|
-
//#region src/utils/links/isLinkWithProtocol.d.ts
|
|
185
|
+
export declare const isLinkHttp: (link: string) => boolean;
|
|
202
186
|
/**
|
|
203
187
|
* Determine a link has protocol or not
|
|
204
188
|
*/
|
|
205
|
-
declare const isLinkWithProtocol: (link: string) => boolean;
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region src/utils/routes/inferRoutePath.d.ts
|
|
189
|
+
export declare const isLinkWithProtocol: (link: string) => boolean;
|
|
208
190
|
/**
|
|
209
191
|
* Infer route path of the given raw path
|
|
210
192
|
*/
|
|
211
|
-
declare const inferRoutePath: (rawPath: string) => string;
|
|
212
|
-
//#endregion
|
|
213
|
-
//#region src/utils/routes/normalizeRoutePath.d.ts
|
|
193
|
+
export declare const inferRoutePath: (rawPath: string) => string;
|
|
214
194
|
/**
|
|
215
195
|
* Normalize the given pathname path to the final route path
|
|
216
196
|
*/
|
|
217
|
-
declare const normalizeRoutePath: (pathname: string, current?: string) => string;
|
|
218
|
-
//#endregion
|
|
219
|
-
//#region src/utils/routes/resolveLocalePath.d.ts
|
|
197
|
+
export declare const normalizeRoutePath: (pathname: string, current?: string) => string;
|
|
220
198
|
/**
|
|
221
199
|
* Resolve the matched locale path of route path
|
|
222
200
|
*/
|
|
223
|
-
declare const resolveLocalePath: (locales: LocaleConfig, routePath: string) => string;
|
|
224
|
-
//#endregion
|
|
225
|
-
//#region src/utils/routes/resolveRoutePathFromUrl.d.ts
|
|
201
|
+
export declare const resolveLocalePath: (locales: LocaleConfig, routePath: string) => string;
|
|
226
202
|
/**
|
|
227
203
|
* For a give URL, remove the origin and the site base to get the route path
|
|
228
204
|
*/
|
|
229
|
-
declare const resolveRoutePathFromUrl: (url: string, base?: string) => string;
|
|
230
|
-
//#endregion
|
|
231
|
-
//#region src/utils/routes/splitPath.d.ts
|
|
205
|
+
export declare const resolveRoutePathFromUrl: (url: string, base?: string) => string;
|
|
232
206
|
/**
|
|
233
207
|
* Split a path into pathname and hashAndQueries
|
|
234
208
|
*/
|
|
235
|
-
declare const splitPath: (path: string) => {
|
|
209
|
+
export declare const splitPath: (path: string) => {
|
|
236
210
|
pathname: string;
|
|
237
211
|
hashAndQueries: string;
|
|
238
212
|
};
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region src/utils/dedupeHead.d.ts
|
|
241
213
|
/**
|
|
242
214
|
* Dedupe head config with identifier
|
|
243
215
|
*
|
|
244
216
|
* Items that appear earlier have higher priority
|
|
245
217
|
*/
|
|
246
|
-
declare const dedupeHead: (head: HeadConfig[]) => HeadConfig[];
|
|
247
|
-
//#endregion
|
|
248
|
-
//#region src/utils/ensureLeadingSlash.d.ts
|
|
218
|
+
export declare const dedupeHead: (head: HeadConfig[]) => HeadConfig[];
|
|
249
219
|
/**
|
|
250
220
|
* Ensure a url string to have leading slash /
|
|
251
221
|
*/
|
|
252
|
-
declare const ensureLeadingSlash: (str: string) => string;
|
|
253
|
-
//#endregion
|
|
254
|
-
//#region src/utils/ensureEndingSlash.d.ts
|
|
222
|
+
export declare const ensureLeadingSlash: (str: string) => string;
|
|
255
223
|
/**
|
|
256
224
|
* Ensure a url string to have ending slash /
|
|
257
225
|
*/
|
|
258
|
-
declare const ensureEndingSlash: (str: string) => string;
|
|
259
|
-
//#endregion
|
|
260
|
-
//#region src/utils/formatDateString.d.ts
|
|
226
|
+
export declare const ensureEndingSlash: (str: string) => string;
|
|
261
227
|
/**
|
|
262
228
|
* Format a date string to `yyyy-MM-dd`
|
|
263
229
|
*/
|
|
264
|
-
declare const formatDateString: (str: string, defaultDateString?: string) => string;
|
|
265
|
-
//#endregion
|
|
266
|
-
//#region src/utils/omit.d.ts
|
|
230
|
+
export declare const formatDateString: (str: string, defaultDateString?: string) => string;
|
|
267
231
|
/**
|
|
268
232
|
* Omit properties from an object
|
|
269
233
|
*/
|
|
270
|
-
declare const omit: <T extends Record<string, unknown>, U extends string[]>(obj: T, ...keys: U) => Omit<T, U[number]>;
|
|
271
|
-
//#endregion
|
|
272
|
-
//#region src/utils/removeEndingSlash.d.ts
|
|
234
|
+
export declare const omit: <T extends Record<string, unknown>, U extends string[]>(obj: T, ...keys: U) => Omit<T, U[number]>;
|
|
273
235
|
/**
|
|
274
236
|
* Remove ending slash / from a string
|
|
275
237
|
*/
|
|
276
|
-
declare const removeEndingSlash: (str: string) => string;
|
|
277
|
-
//#endregion
|
|
278
|
-
//#region src/utils/removeLeadingSlash.d.ts
|
|
238
|
+
export declare const removeEndingSlash: (str: string) => string;
|
|
279
239
|
/**
|
|
280
240
|
* Remove leading slash / from a string
|
|
281
241
|
*/
|
|
282
|
-
declare const removeLeadingSlash: (str: string) => string;
|
|
283
|
-
//#endregion
|
|
284
|
-
//#region src/utils/resolveHeadIdentifier.d.ts
|
|
242
|
+
export declare const removeLeadingSlash: (str: string) => string;
|
|
285
243
|
/**
|
|
286
244
|
* Resolve identifier of a tag, to avoid duplicated tags in `<head>`
|
|
287
245
|
*/
|
|
288
|
-
declare const resolveHeadIdentifier: ([tag, attrs, content]: HeadConfig) => string | null;
|
|
289
|
-
//#endregion
|
|
290
|
-
//#region src/utils/typeGuards.d.ts
|
|
246
|
+
export declare const resolveHeadIdentifier: ([tag, attrs, content]: HeadConfig) => string | null;
|
|
291
247
|
/**
|
|
292
248
|
* Check if a value is a function
|
|
293
249
|
*/
|
|
294
|
-
declare const isFunction: (val: unknown) => val is Function;
|
|
250
|
+
export declare const isFunction: (val: unknown) => val is Function;
|
|
295
251
|
/**
|
|
296
252
|
* Check if a value is plain object, with generic type support
|
|
297
253
|
*/
|
|
298
|
-
declare const isPlainObject: <T extends Record<any, any> = Record<any, any>>(val: unknown) => val is T;
|
|
254
|
+
export declare const isPlainObject: <T extends Record<any, any> = Record<any, any>>(val: unknown) => val is T;
|
|
299
255
|
/**
|
|
300
256
|
* Check if a value is a string
|
|
301
257
|
*/
|
|
302
|
-
declare const isString: (val: unknown) => val is string;
|
|
303
|
-
|
|
304
|
-
export { HeadAttrsConfig, HeadConfig, HeadTag, HeadTagEmpty, HeadTagNonEmpty, LocaleConfig, LocaleData, PageBase, PageData, PageFrontmatter, PageHeader, SiteData, SiteLocaleConfig, SiteLocaleData, VuepressSSRContext, dedupeHead, ensureEndingSlash, ensureLeadingSlash, formatDateString, inferRoutePath, isFunction, isLinkExternal, isLinkHttp, isLinkWithProtocol, isPlainObject, isString, normalizeRoutePath, omit, removeEndingSlash, removeLeadingSlash, resolveHeadIdentifier, resolveLocalePath, resolveRoutePathFromUrl, splitPath };
|
|
258
|
+
export declare const isString: (val: unknown) => val is string;
|
|
259
|
+
export type { HeadAttrsConfig, HeadConfig, HeadTag, HeadTagEmpty, HeadTagNonEmpty, LocaleConfig, LocaleData, PageBase, PageData, PageFrontmatter, PageHeader, SiteData, SiteLocaleConfig, SiteLocaleData, VuepressSSRContext };
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
// src/utils/links/isLinkWithProtocol.ts
|
|
2
2
|
/**
|
|
3
3
|
* Determine a link has protocol or not
|
|
4
4
|
*/
|
|
5
5
|
const isLinkWithProtocol = (link) => /^[a-z][a-z0-9+.-]*:/.test(link) || link.startsWith("//");
|
|
6
|
-
|
|
7
|
-
//#region src/utils/links/isLinkExternal.ts
|
|
6
|
+
// src/utils/links/isLinkExternal.ts
|
|
8
7
|
const markdownLinkRegexp = /.md((\?|#).*)?$/;
|
|
9
8
|
/**
|
|
10
9
|
* Determine a link is external or not
|
|
11
10
|
*/
|
|
12
11
|
const isLinkExternal = (link, base = "/") => isLinkWithProtocol(link) || link.startsWith("/") && !link.startsWith(base) && !markdownLinkRegexp.test(link);
|
|
13
|
-
|
|
14
|
-
//#region src/utils/links/isLinkHttp.ts
|
|
12
|
+
// src/utils/links/isLinkHttp.ts
|
|
15
13
|
/**
|
|
16
14
|
* Determine a link is http link or not
|
|
17
15
|
*
|
|
@@ -20,8 +18,7 @@ const isLinkExternal = (link, base = "/") => isLinkWithProtocol(link) || link.st
|
|
|
20
18
|
* - //github.com
|
|
21
19
|
*/
|
|
22
20
|
const isLinkHttp = (link) => /^(https?:)?\/\//.test(link);
|
|
23
|
-
|
|
24
|
-
//#region src/utils/routes/inferRoutePath.ts
|
|
21
|
+
// src/utils/routes/inferRoutePath.ts
|
|
25
22
|
/**
|
|
26
23
|
* Infer route path of the given raw path
|
|
27
24
|
*/
|
|
@@ -33,8 +30,7 @@ const inferRoutePath = (rawPath) => {
|
|
|
33
30
|
if (routePath.endsWith("/index.html")) routePath = routePath.substring(0, routePath.length - 10);
|
|
34
31
|
return routePath;
|
|
35
32
|
};
|
|
36
|
-
|
|
37
|
-
//#region src/utils/routes/normalizeRoutePath.ts
|
|
33
|
+
// src/utils/routes/normalizeRoutePath.ts
|
|
38
34
|
const FAKE_HOST = "http://.";
|
|
39
35
|
/**
|
|
40
36
|
* Normalize the given pathname path to the final route path
|
|
@@ -46,8 +42,7 @@ const normalizeRoutePath = (pathname, current) => {
|
|
|
46
42
|
}
|
|
47
43
|
return inferRoutePath(pathname);
|
|
48
44
|
};
|
|
49
|
-
|
|
50
|
-
//#region src/utils/routes/resolveLocalePath.ts
|
|
45
|
+
// src/utils/routes/resolveLocalePath.ts
|
|
51
46
|
/**
|
|
52
47
|
* Resolve the matched locale path of route path
|
|
53
48
|
*/
|
|
@@ -60,8 +55,7 @@ const resolveLocalePath = (locales, routePath) => {
|
|
|
60
55
|
for (const localePath of localePaths) if (routePath.startsWith(localePath)) return localePath;
|
|
61
56
|
return "/";
|
|
62
57
|
};
|
|
63
|
-
|
|
64
|
-
//#region src/utils/routes/resolveRoutePathFromUrl.ts
|
|
58
|
+
// src/utils/routes/resolveRoutePathFromUrl.ts
|
|
65
59
|
/**
|
|
66
60
|
* For a give URL, remove the origin and the site base to get the route path
|
|
67
61
|
*/
|
|
@@ -69,8 +63,7 @@ const resolveRoutePathFromUrl = (url, base = "/") => {
|
|
|
69
63
|
const pathname = url.replace(/^(?:https?:)?\/\/[^/]*/, "");
|
|
70
64
|
return pathname.startsWith(base) ? `/${pathname.slice(base.length)}` : pathname;
|
|
71
65
|
};
|
|
72
|
-
|
|
73
|
-
//#region src/utils/routes/splitPath.ts
|
|
66
|
+
// src/utils/routes/splitPath.ts
|
|
74
67
|
const SPLIT_CHAR_REGEXP = /(#|\?)/;
|
|
75
68
|
/**
|
|
76
69
|
* Split a path into pathname and hashAndQueries
|
|
@@ -82,8 +75,7 @@ const splitPath = (path) => {
|
|
|
82
75
|
hashAndQueries: hashAndQueries.join("")
|
|
83
76
|
};
|
|
84
77
|
};
|
|
85
|
-
|
|
86
|
-
//#region src/utils/resolveHeadIdentifier.ts
|
|
78
|
+
// src/utils/resolveHeadIdentifier.ts
|
|
87
79
|
const TAGS_ALLOWED = [
|
|
88
80
|
"link",
|
|
89
81
|
"meta",
|
|
@@ -110,8 +102,7 @@ const resolveHeadIdentifier = ([tag, attrs, content]) => {
|
|
|
110
102
|
content
|
|
111
103
|
]);
|
|
112
104
|
};
|
|
113
|
-
|
|
114
|
-
//#region src/utils/dedupeHead.ts
|
|
105
|
+
// src/utils/dedupeHead.ts
|
|
115
106
|
/**
|
|
116
107
|
* Dedupe head config with identifier
|
|
117
108
|
*
|
|
@@ -129,20 +120,17 @@ const dedupeHead = (head) => {
|
|
|
129
120
|
});
|
|
130
121
|
return result;
|
|
131
122
|
};
|
|
132
|
-
|
|
133
|
-
//#region src/utils/ensureLeadingSlash.ts
|
|
123
|
+
// src/utils/ensureLeadingSlash.ts
|
|
134
124
|
/**
|
|
135
125
|
* Ensure a url string to have leading slash /
|
|
136
126
|
*/
|
|
137
127
|
const ensureLeadingSlash = (str) => str.startsWith("/") ? str : `/${str}`;
|
|
138
|
-
|
|
139
|
-
//#region src/utils/ensureEndingSlash.ts
|
|
128
|
+
// src/utils/ensureEndingSlash.ts
|
|
140
129
|
/**
|
|
141
130
|
* Ensure a url string to have ending slash /
|
|
142
131
|
*/
|
|
143
132
|
const ensureEndingSlash = (str) => str.endsWith("/") || str.endsWith(".html") ? str : `${str}/`;
|
|
144
|
-
|
|
145
|
-
//#region src/utils/formatDateString.ts
|
|
133
|
+
// src/utils/formatDateString.ts
|
|
146
134
|
/**
|
|
147
135
|
* Format a date string to `yyyy-MM-dd`
|
|
148
136
|
*/
|
|
@@ -156,8 +144,7 @@ const formatDateString = (str, defaultDateString = "") => {
|
|
|
156
144
|
dayStr.padStart(2, "0")
|
|
157
145
|
].join("-");
|
|
158
146
|
};
|
|
159
|
-
|
|
160
|
-
//#region src/utils/omit.ts
|
|
147
|
+
// src/utils/omit.ts
|
|
161
148
|
/**
|
|
162
149
|
* Omit properties from an object
|
|
163
150
|
*/
|
|
@@ -166,20 +153,17 @@ const omit = (obj, ...keys) => {
|
|
|
166
153
|
for (const key of keys) delete result[key];
|
|
167
154
|
return result;
|
|
168
155
|
};
|
|
169
|
-
|
|
170
|
-
//#region src/utils/removeEndingSlash.ts
|
|
156
|
+
// src/utils/removeEndingSlash.ts
|
|
171
157
|
/**
|
|
172
158
|
* Remove ending slash / from a string
|
|
173
159
|
*/
|
|
174
160
|
const removeEndingSlash = (str) => str.endsWith("/") ? str.slice(0, -1) : str;
|
|
175
|
-
|
|
176
|
-
//#region src/utils/removeLeadingSlash.ts
|
|
161
|
+
// src/utils/removeLeadingSlash.ts
|
|
177
162
|
/**
|
|
178
163
|
* Remove leading slash / from a string
|
|
179
164
|
*/
|
|
180
165
|
const removeLeadingSlash = (str) => str.startsWith("/") ? str.slice(1) : str;
|
|
181
|
-
|
|
182
|
-
//#region src/utils/typeGuards.ts
|
|
166
|
+
// src/utils/typeGuards.ts
|
|
183
167
|
/**
|
|
184
168
|
* Check if a value is a function
|
|
185
169
|
*/
|
|
@@ -192,5 +176,4 @@ const isPlainObject = (val) => Object.prototype.toString.call(val) === "[object
|
|
|
192
176
|
* Check if a value is a string
|
|
193
177
|
*/
|
|
194
178
|
const isString = (val) => typeof val === "string";
|
|
195
|
-
//#endregion
|
|
196
179
|
export { dedupeHead, ensureEndingSlash, ensureLeadingSlash, formatDateString, inferRoutePath, isFunction, isLinkExternal, isLinkHttp, isLinkWithProtocol, isPlainObject, isString, normalizeRoutePath, omit, removeEndingSlash, removeLeadingSlash, resolveHeadIdentifier, resolveLocalePath, resolveRoutePathFromUrl, splitPath };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/shared",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.32",
|
|
4
4
|
"description": "Utils that shared between VuePress node and client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shared",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@mdit-vue/types": "^
|
|
35
|
+
"@mdit-vue/types": "^4.0.0"
|
|
36
36
|
},
|
|
37
37
|
"tsdown": {
|
|
38
38
|
"dts": true,
|