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