@vuepress/shared 2.0.0-rc.2 → 2.0.0-rc.21

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 CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  ## Documentation
7
7
 
8
- https://v2.vuepress.vuejs.org
8
+ https://vuepress.vuejs.org
9
9
 
10
10
  ## License
11
11
 
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 = HeadTagNonEmpty | HeadTagEmpty;
12
+ type HeadTag = HeadTagEmpty | HeadTagNonEmpty;
13
13
  /**
14
14
  * Non-empty tags in `<head>`
15
15
  */
16
- type HeadTagNonEmpty = 'title' | 'style' | 'script' | 'noscript' | 'template';
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, string | boolean>;
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<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;
43
+ interface PageBase<ExtraPageFrontmatter extends Record<string, unknown> = Record<string, unknown>> {
52
44
  /**
53
45
  * Route path of the page
54
46
  *
@@ -72,28 +64,24 @@ interface PageBase<ExtraPageFrontmatter extends Record<any, any> = Record<string
72
64
  * Front matter of the page
73
65
  */
74
66
  frontmatter: PageFrontmatter<ExtraPageFrontmatter>;
75
- /**
76
- * Headers of the page
77
- */
78
- headers: PageHeader[];
79
67
  }
80
68
  /**
81
69
  * Vuepress page data
82
70
  */
83
- type PageData<ExtraPageData extends Record<any, any> = Record<never, never>, ExtraPageFrontmatter extends Record<any, any> = Record<string, unknown>> = PageBase<ExtraPageFrontmatter> & ExtraPageData;
71
+ type PageData<ExtraPageData extends Record<string, unknown> = Record<string, unknown>, ExtraPageFrontmatter extends Record<string, unknown> = Record<string, unknown>> = ExtraPageData & PageBase<ExtraPageFrontmatter>;
84
72
  /**
85
73
  * Vuepress page frontmatter
86
74
  *
87
75
  * Notice that frontmatter is parsed from yaml or other languages,
88
76
  * so we cannot guarantee the type safety
89
77
  */
90
- type PageFrontmatter<T extends Record<any, any> = Record<string, unknown>> = Partial<T> & {
91
- date?: string | Date;
78
+ type PageFrontmatter<T extends Record<string, unknown> = Record<string, unknown>> = Partial<T> & {
79
+ date?: Date | string;
92
80
  description?: string;
93
81
  head?: HeadConfig[];
94
82
  lang?: string;
95
83
  layout?: string;
96
- permalink?: string;
84
+ permalink?: string | null;
97
85
  permalinkPattern?: string | null;
98
86
  routeMeta?: Record<string, unknown>;
99
87
  title?: string;
@@ -167,7 +155,7 @@ interface SiteLocaleData {
167
155
  /**
168
156
  * Head config
169
157
  *
170
- * Descibe the tags to be appended into the `<head>` tag
158
+ * Describe the tags to be appended into the `<head>` tag
171
159
  *
172
160
  * @default []
173
161
  *
@@ -190,50 +178,73 @@ interface VuepressSSRContext {
190
178
  }
191
179
 
192
180
  /**
193
- * Dedupe head config with identifier
181
+ * Determine a link is external or not
182
+ */
183
+ declare const isLinkExternal: (link: string, base?: string) => boolean;
184
+
185
+ /**
186
+ * Determine a link is http link or not
194
187
  *
195
- * Items that appear earlier have higher priority
188
+ * - http://github.com
189
+ * - https://github.com
190
+ * - //github.com
196
191
  */
197
- declare const dedupeHead: (head: HeadConfig[]) => HeadConfig[];
192
+ declare const isLinkHttp: (link: string) => boolean;
198
193
 
199
194
  /**
200
- * Ensure a url string to have leading slash /
195
+ * Determine a link has protocol or not
201
196
  */
202
- declare const ensureLeadingSlash: (str: string) => string;
197
+ declare const isLinkWithProtocol: (link: string) => boolean;
203
198
 
204
199
  /**
205
- * Ensure a url string to have ending slash /
200
+ * Infer route path of the given raw path
206
201
  */
207
- declare const ensureEndingSlash: (str: string) => string;
202
+ declare const inferRoutePath: (rawPath: string) => string;
208
203
 
209
204
  /**
210
- * Format a date string to `yyyy-MM-dd`
205
+ * Normalize the given pathname path to the final route path
211
206
  */
212
- declare const formatDateString: (str: string, defaultDateString?: string) => string;
207
+ declare const normalizeRoutePath: (pathname: string, current?: string) => string;
213
208
 
214
209
  /**
215
- * Determine a link is external or not
210
+ * Resolve the matched locale path of route path
216
211
  */
217
- declare const isLinkExternal: (link: string, base?: string) => boolean;
212
+ declare const resolveLocalePath: (locales: LocaleConfig, routePath: string) => string;
218
213
 
219
214
  /**
220
- * Determine a link is http link or not
215
+ * For a give URL, remove the origin and the site base to get the route path
216
+ */
217
+ declare const resolveRoutePathFromUrl: (url: string, base?: string) => string;
218
+
219
+ /**
220
+ * Split a path into pathname and hashAndQueries
221
+ */
222
+ declare const splitPath: (path: string) => {
223
+ pathname: string;
224
+ hashAndQueries: string;
225
+ };
226
+
227
+ /**
228
+ * Dedupe head config with identifier
221
229
  *
222
- * - http://github.com
223
- * - https://github.com
224
- * - //github.com
230
+ * Items that appear earlier have higher priority
225
231
  */
226
- declare const isLinkHttp: (link: string) => boolean;
232
+ declare const dedupeHead: (head: HeadConfig[]) => HeadConfig[];
227
233
 
228
234
  /**
229
- * Determine a link has protocol or not
235
+ * Ensure a url string to have leading slash /
230
236
  */
231
- declare const isLinkWithProtocol: (link: string) => boolean;
237
+ declare const ensureLeadingSlash: (str: string) => string;
232
238
 
233
239
  /**
234
- * Check if a value is plain object, with generic type support
240
+ * Ensure a url string to have ending slash /
235
241
  */
236
- declare const isPlainObject: <T extends Record<any, any> = Record<any, any>>(val: unknown) => val is T;
242
+ declare const ensureEndingSlash: (str: string) => string;
243
+
244
+ /**
245
+ * Format a date string to `yyyy-MM-dd`
246
+ */
247
+ declare const formatDateString: (str: string, defaultDateString?: string) => string;
237
248
 
238
249
  /**
239
250
  * Omit properties from an object
@@ -255,20 +266,17 @@ declare const removeLeadingSlash: (str: string) => string;
255
266
  */
256
267
  declare const resolveHeadIdentifier: ([tag, attrs, content]: HeadConfig) => string | null;
257
268
 
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
269
  /**
266
270
  * Check if a value is a function
267
271
  */
268
272
  declare const isFunction: (val: unknown) => val is Function;
273
+ /**
274
+ * Check if a value is plain object, with generic type support
275
+ */
276
+ declare const isPlainObject: <T extends Record<any, any> = Record<any, any>>(val: unknown) => val is T;
269
277
  /**
270
278
  * Check if a value is a string
271
279
  */
272
280
  declare const isString: (val: unknown) => val is string;
273
281
 
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 };
282
+ 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[0] === "/" ? str : `/${str}`;
113
+ var ensureLeadingSlash = (str) => str.startsWith("/") ? str : `/${str}`;
45
114
 
46
115
  // src/utils/ensureEndingSlash.ts
47
- var ensureEndingSlash = (str) => str[str.length - 1] === "/" || str.endsWith(".html") ? 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[str.length - 1] === "/" ? str.slice(0, -1) : 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[0] === "/" ? str.slice(1) : 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.2",
3
+ "version": "2.0.0-rc.21",
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.0.0"
32
+ "@mdit-vue/types": "^2.1.4"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"