@vuepress/shared 2.0.0-rc.1 → 2.0.0-rc.10
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 +13 -11
- package/dist/index.js +36 -13
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -41,14 +41,6 @@ type LocaleData = Record<never, never>;
|
|
|
41
41
|
* Base type of vuepress page
|
|
42
42
|
*/
|
|
43
43
|
interface PageBase<ExtraPageFrontmatter extends Record<any, any> = Record<string, unknown>> {
|
|
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;
|
|
52
44
|
/**
|
|
53
45
|
* Route path of the page
|
|
54
46
|
*
|
|
@@ -93,7 +85,7 @@ type PageFrontmatter<T extends Record<any, any> = Record<string, unknown>> = Par
|
|
|
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
|
*
|
|
@@ -211,6 +203,11 @@ declare const ensureEndingSlash: (str: string) => string;
|
|
|
211
203
|
*/
|
|
212
204
|
declare const formatDateString: (str: string, defaultDateString?: string) => string;
|
|
213
205
|
|
|
206
|
+
/**
|
|
207
|
+
* Infer route path according to the given (markdown file) path
|
|
208
|
+
*/
|
|
209
|
+
declare const inferRoutePath: (path: string) => string;
|
|
210
|
+
|
|
214
211
|
/**
|
|
215
212
|
* Determine a link is external or not
|
|
216
213
|
*/
|
|
@@ -235,6 +232,11 @@ declare const isLinkWithProtocol: (link: string) => boolean;
|
|
|
235
232
|
*/
|
|
236
233
|
declare const isPlainObject: <T extends Record<any, any> = Record<any, any>>(val: unknown) => val is T;
|
|
237
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Normalize the given path to the final route path
|
|
237
|
+
*/
|
|
238
|
+
declare const normalizeRoutePath: (path: string, current?: string) => string;
|
|
239
|
+
|
|
238
240
|
/**
|
|
239
241
|
* Omit properties from an object
|
|
240
242
|
*/
|
|
@@ -271,4 +273,4 @@ declare const isFunction: (val: unknown) => val is Function;
|
|
|
271
273
|
*/
|
|
272
274
|
declare const isString: (val: unknown) => val is string;
|
|
273
275
|
|
|
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 };
|
|
276
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -56,27 +56,48 @@ var formatDateString = (str, defaultDateString = "") => {
|
|
|
56
56
|
return [yearStr, monthStr.padStart(2, "0"), dayStr.padStart(2, "0")].join("-");
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
// src/utils/
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
// src/utils/inferRoutePath.ts
|
|
60
|
+
var inferRoutePath = (path) => {
|
|
61
|
+
if (!path || path.endsWith("/"))
|
|
62
|
+
return path;
|
|
63
|
+
let routePath = path.replace(/(^|\/)README.md$/i, "$1index.html");
|
|
64
|
+
if (routePath.endsWith(".md")) {
|
|
65
|
+
routePath = routePath.substring(0, routePath.length - 3) + ".html";
|
|
66
|
+
} else if (!routePath.endsWith(".html")) {
|
|
67
|
+
routePath = routePath + ".html";
|
|
67
68
|
}
|
|
68
|
-
if (
|
|
69
|
-
|
|
69
|
+
if (routePath.endsWith("/index.html")) {
|
|
70
|
+
routePath = routePath.substring(0, routePath.length - 10);
|
|
70
71
|
}
|
|
71
|
-
return
|
|
72
|
+
return routePath;
|
|
72
73
|
};
|
|
73
74
|
|
|
74
75
|
// src/utils/isLinkWithProtocol.ts
|
|
75
|
-
var isLinkWithProtocol = (link) => /^[a-z][a-z0-9+.-]*:/.test(link);
|
|
76
|
+
var isLinkWithProtocol = (link) => /^[a-z][a-z0-9+.-]*:/.test(link) || link.startsWith("//");
|
|
77
|
+
|
|
78
|
+
// src/utils/isLinkExternal.ts
|
|
79
|
+
var markdownLinkRegexp = /.md((\?|#).*)?$/;
|
|
80
|
+
var isLinkExternal = (link, base = "/") => isLinkWithProtocol(link) || // absolute link that does not start with `base` and does not end with `.md`
|
|
81
|
+
link.startsWith("/") && !link.startsWith(base) && !markdownLinkRegexp.test(link);
|
|
82
|
+
|
|
83
|
+
// src/utils/isLinkHttp.ts
|
|
84
|
+
var isLinkHttp = (link) => /^(https?:)?\/\//.test(link);
|
|
76
85
|
|
|
77
86
|
// src/utils/isPlainObject.ts
|
|
78
87
|
var isPlainObject = (val) => Object.prototype.toString.call(val) === "[object Object]";
|
|
79
88
|
|
|
89
|
+
// src/utils/normalizeRoutePath.ts
|
|
90
|
+
var FAKE_HOST = "http://.";
|
|
91
|
+
var normalizeRoutePath = (path, current) => {
|
|
92
|
+
if (!path.startsWith("/") && current) {
|
|
93
|
+
const loc = current.slice(0, current.lastIndexOf("/"));
|
|
94
|
+
const { pathname: pathname2, search, hash } = new URL(`${loc}/${path}`, FAKE_HOST);
|
|
95
|
+
return inferRoutePath(pathname2) + search + hash;
|
|
96
|
+
}
|
|
97
|
+
const [pathname, ...queryAndHash] = path.split(/(\?|#)/);
|
|
98
|
+
return inferRoutePath(pathname) + queryAndHash.join("");
|
|
99
|
+
};
|
|
100
|
+
|
|
80
101
|
// src/utils/omit.ts
|
|
81
102
|
var omit = (obj, ...keys) => {
|
|
82
103
|
const result = { ...obj };
|
|
@@ -111,7 +132,7 @@ var resolveLocalePath = (locales, routePath) => {
|
|
|
111
132
|
|
|
112
133
|
// src/utils/resolveRoutePathFromUrl.ts
|
|
113
134
|
var resolveRoutePathFromUrl = (url, base = "/") => {
|
|
114
|
-
const pathname = url.replace(/^(https?:)?\/\/[^/]*/, "");
|
|
135
|
+
const pathname = url.replace(/^(?:https?:)?\/\/[^/]*/, "");
|
|
115
136
|
return pathname.startsWith(base) ? `/${pathname.slice(base.length)}` : pathname;
|
|
116
137
|
};
|
|
117
138
|
|
|
@@ -123,12 +144,14 @@ export {
|
|
|
123
144
|
ensureEndingSlash,
|
|
124
145
|
ensureLeadingSlash,
|
|
125
146
|
formatDateString,
|
|
147
|
+
inferRoutePath,
|
|
126
148
|
isFunction,
|
|
127
149
|
isLinkExternal,
|
|
128
150
|
isLinkHttp,
|
|
129
151
|
isLinkWithProtocol,
|
|
130
152
|
isPlainObject,
|
|
131
153
|
isString,
|
|
154
|
+
normalizeRoutePath,
|
|
132
155
|
omit,
|
|
133
156
|
removeEndingSlash,
|
|
134
157
|
removeLeadingSlash,
|
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.10",
|
|
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"
|