@vuepress/shared 2.0.0-rc.11 → 2.0.0-rc.12

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 CHANGED
@@ -182,60 +182,73 @@ interface VuepressSSRContext {
182
182
  }
183
183
 
184
184
  /**
185
- * Dedupe head config with identifier
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
186
191
  *
187
- * Items that appear earlier have higher priority
192
+ * - http://github.com
193
+ * - https://github.com
194
+ * - //github.com
188
195
  */
189
- declare const dedupeHead: (head: HeadConfig[]) => HeadConfig[];
196
+ declare const isLinkHttp: (link: string) => boolean;
190
197
 
191
198
  /**
192
- * Ensure a url string to have leading slash /
199
+ * Determine a link has protocol or not
193
200
  */
194
- declare const ensureLeadingSlash: (str: string) => string;
201
+ declare const isLinkWithProtocol: (link: string) => boolean;
195
202
 
196
203
  /**
197
- * Ensure a url string to have ending slash /
204
+ * Infer route path according to the given (markdown file) path
198
205
  */
199
- declare const ensureEndingSlash: (str: string) => string;
206
+ declare const inferRoutePath: (path: string) => string;
200
207
 
201
208
  /**
202
- * Format a date string to `yyyy-MM-dd`
209
+ * Normalize the given pathname path to the final route path
203
210
  */
204
- declare const formatDateString: (str: string, defaultDateString?: string) => string;
211
+ declare const normalizeRoutePath: (pathname: string, current?: string) => string;
205
212
 
206
213
  /**
207
- * Infer route path according to the given (markdown file) path
214
+ * Resolve the matched locale path of route path
208
215
  */
209
- declare const inferRoutePath: (path: string) => string;
216
+ declare const resolveLocalePath: (locales: LocaleConfig, routePath: string) => string;
210
217
 
211
218
  /**
212
- * Determine a link is external or not
219
+ * For a give URL, remove the origin and the site base to get the route path
213
220
  */
214
- declare const isLinkExternal: (link: string, base?: string) => boolean;
221
+ declare const resolveRoutePathFromUrl: (url: string, base?: string) => string;
215
222
 
216
223
  /**
217
- * Determine a link is http link or not
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
218
233
  *
219
- * - http://github.com
220
- * - https://github.com
221
- * - //github.com
234
+ * Items that appear earlier have higher priority
222
235
  */
223
- declare const isLinkHttp: (link: string) => boolean;
236
+ declare const dedupeHead: (head: HeadConfig[]) => HeadConfig[];
224
237
 
225
238
  /**
226
- * Determine a link has protocol or not
239
+ * Ensure a url string to have leading slash /
227
240
  */
228
- declare const isLinkWithProtocol: (link: string) => boolean;
241
+ declare const ensureLeadingSlash: (str: string) => string;
229
242
 
230
243
  /**
231
- * Check if a value is plain object, with generic type support
244
+ * Ensure a url string to have ending slash /
232
245
  */
233
- declare const isPlainObject: <T extends Record<any, any> = Record<any, any>>(val: unknown) => val is T;
246
+ declare const ensureEndingSlash: (str: string) => string;
234
247
 
235
248
  /**
236
- * Normalize the given path to the final route path
249
+ * Format a date string to `yyyy-MM-dd`
237
250
  */
238
- declare const normalizeRoutePath: (path: string, current?: string) => string;
251
+ declare const formatDateString: (str: string, defaultDateString?: string) => string;
239
252
 
240
253
  /**
241
254
  * Omit properties from an object
@@ -257,20 +270,17 @@ declare const removeLeadingSlash: (str: string) => string;
257
270
  */
258
271
  declare const resolveHeadIdentifier: ([tag, attrs, content]: HeadConfig) => string | null;
259
272
 
260
- /**
261
- * Resolve the matched locale path of route path
262
- */
263
- declare const resolveLocalePath: (locales: LocaleConfig, routePath: string) => string;
264
-
265
- declare const resolveRoutePathFromUrl: (url: string, base?: string) => string;
266
-
267
273
  /**
268
274
  * Check if a value is a function
269
275
  */
270
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;
271
281
  /**
272
282
  * Check if a value is a string
273
283
  */
274
284
  declare const isString: (val: unknown) => val is string;
275
285
 
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 };
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,73 @@
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 = (path) => {
14
+ if (!path || path.endsWith("/"))
15
+ return path;
16
+ let routePath = path.replace(/(^|\/)README.md$/i, "$1index.html");
17
+ if (routePath.endsWith(".md")) {
18
+ routePath = routePath.substring(0, routePath.length - 3) + ".html";
19
+ } else if (!routePath.endsWith(".html")) {
20
+ routePath = routePath + ".html";
21
+ }
22
+ if (routePath.endsWith("/index.html")) {
23
+ routePath = routePath.substring(0, routePath.length - 10);
24
+ }
25
+ return routePath;
26
+ };
27
+
28
+ // src/utils/routes/normalizeRoutePath.ts
29
+ var FAKE_HOST = "http://.";
30
+ var normalizeRoutePath = (pathname, current) => {
31
+ if (!pathname.startsWith("/") && current) {
32
+ const loc = current.slice(0, current.lastIndexOf("/"));
33
+ return inferRoutePath(new URL(`${loc}/${pathname}`, FAKE_HOST).pathname);
34
+ }
35
+ return inferRoutePath(pathname);
36
+ };
37
+
38
+ // src/utils/routes/resolveLocalePath.ts
39
+ var resolveLocalePath = (locales, routePath) => {
40
+ const localePaths = Object.keys(locales).sort((a, b) => {
41
+ const levelDelta = b.split("/").length - a.split("/").length;
42
+ if (levelDelta !== 0) {
43
+ return levelDelta;
44
+ }
45
+ return b.length - a.length;
46
+ });
47
+ for (const localePath of localePaths) {
48
+ if (routePath.startsWith(localePath)) {
49
+ return localePath;
50
+ }
51
+ }
52
+ return "/";
53
+ };
54
+
55
+ // src/utils/routes/resolveRoutePathFromUrl.ts
56
+ var resolveRoutePathFromUrl = (url, base = "/") => {
57
+ const pathname = url.replace(/^(?:https?:)?\/\/[^/]*/, "");
58
+ return pathname.startsWith(base) ? `/${pathname.slice(base.length)}` : pathname;
59
+ };
60
+
61
+ // src/utils/routes/splitPath.ts
62
+ var SPLIT_CHAR_REGEXP = /(#|\?)/;
63
+ var splitPath = (path) => {
64
+ const [pathname, ...hashAndQueries] = path.split(SPLIT_CHAR_REGEXP);
65
+ return {
66
+ pathname,
67
+ hashAndQueries: hashAndQueries.join("")
68
+ };
69
+ };
70
+
1
71
  // src/utils/resolveHeadIdentifier.ts
2
72
  var TAGS_ALLOWED = ["link", "meta", "script", "style", "noscript", "template"];
3
73
  var TAGS_UNIQUE = ["title", "base"];
@@ -56,48 +126,6 @@ var formatDateString = (str, defaultDateString = "") => {
56
126
  return [yearStr, monthStr.padStart(2, "0"), dayStr.padStart(2, "0")].join("-");
57
127
  };
58
128
 
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";
68
- }
69
- if (routePath.endsWith("/index.html")) {
70
- routePath = routePath.substring(0, routePath.length - 10);
71
- }
72
- return routePath;
73
- };
74
-
75
- // src/utils/isLinkWithProtocol.ts
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);
85
-
86
- // src/utils/isPlainObject.ts
87
- var isPlainObject = (val) => Object.prototype.toString.call(val) === "[object Object]";
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
-
101
129
  // src/utils/omit.ts
102
130
  var omit = (obj, ...keys) => {
103
131
  const result = { ...obj };
@@ -113,31 +141,9 @@ var removeEndingSlash = (str) => str[str.length - 1] === "/" ? str.slice(0, -1)
113
141
  // src/utils/removeLeadingSlash.ts
114
142
  var removeLeadingSlash = (str) => str[0] === "/" ? str.slice(1) : str;
115
143
 
116
- // src/utils/resolveLocalePath.ts
117
- var resolveLocalePath = (locales, routePath) => {
118
- const localePaths = Object.keys(locales).sort((a, b) => {
119
- const levelDelta = b.split("/").length - a.split("/").length;
120
- if (levelDelta !== 0) {
121
- return levelDelta;
122
- }
123
- return b.length - a.length;
124
- });
125
- for (const localePath of localePaths) {
126
- if (routePath.startsWith(localePath)) {
127
- return localePath;
128
- }
129
- }
130
- return "/";
131
- };
132
-
133
- // src/utils/resolveRoutePathFromUrl.ts
134
- var resolveRoutePathFromUrl = (url, base = "/") => {
135
- const pathname = url.replace(/^(?:https?:)?\/\/[^/]*/, "");
136
- return pathname.startsWith(base) ? `/${pathname.slice(base.length)}` : pathname;
137
- };
138
-
139
144
  // src/utils/typeGuards.ts
140
145
  var isFunction = (val) => typeof val === "function";
146
+ var isPlainObject = (val) => Object.prototype.toString.call(val) === "[object Object]";
141
147
  var isString = (val) => typeof val === "string";
142
148
  export {
143
149
  dedupeHead,
@@ -157,5 +163,6 @@ export {
157
163
  removeLeadingSlash,
158
164
  resolveHeadIdentifier,
159
165
  resolveLocalePath,
160
- resolveRoutePathFromUrl
166
+ resolveRoutePathFromUrl,
167
+ splitPath
161
168
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/shared",
3
- "version": "2.0.0-rc.11",
3
+ "version": "2.0.0-rc.12",
4
4
  "description": "Utils that shared between VuePress node and client",
5
5
  "keywords": [
6
6
  "vuepress",