@vuepress/shared 2.0.0-rc.0 → 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/LICENSE +1 -1
- package/README.md +12 -0
- package/dist/index.d.ts +23 -13
- package/dist/index.js +60 -27
- package/package.json +5 -6
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2018-present,
|
|
3
|
+
Copyright (c) 2018-present, VuePress Community
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @vuepress/shared
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@vuepress/shared)
|
|
4
|
+
[](https://github.com/vuepress/core/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
## Documentation
|
|
7
|
+
|
|
8
|
+
https://v2.vuepress.vuejs.org
|
|
9
|
+
|
|
10
|
+
## License
|
|
11
|
+
|
|
12
|
+
[MIT](https://github.com/vuepress/core/blob/main/LICENSE)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { MarkdownItHeader } from '@mdit-vue/types';
|
|
2
|
-
export { isArray, isFunction, isString } from '@vue/shared';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Config for `<head>` tags
|
|
@@ -42,14 +41,6 @@ type LocaleData = Record<never, never>;
|
|
|
42
41
|
* Base type of vuepress page
|
|
43
42
|
*/
|
|
44
43
|
interface PageBase<ExtraPageFrontmatter extends Record<any, any> = Record<string, unknown>> {
|
|
45
|
-
/**
|
|
46
|
-
* Identifier of the page
|
|
47
|
-
*
|
|
48
|
-
* Will also be used as the component name
|
|
49
|
-
*
|
|
50
|
-
* @example 'v-foobar'
|
|
51
|
-
*/
|
|
52
|
-
key: string;
|
|
53
44
|
/**
|
|
54
45
|
* Route path of the page
|
|
55
46
|
*
|
|
@@ -94,7 +85,7 @@ type PageFrontmatter<T extends Record<any, any> = Record<string, unknown>> = Par
|
|
|
94
85
|
head?: HeadConfig[];
|
|
95
86
|
lang?: string;
|
|
96
87
|
layout?: string;
|
|
97
|
-
permalink?: string;
|
|
88
|
+
permalink?: string | null;
|
|
98
89
|
permalinkPattern?: string | null;
|
|
99
90
|
routeMeta?: Record<string, unknown>;
|
|
100
91
|
title?: string;
|
|
@@ -168,7 +159,7 @@ interface SiteLocaleData {
|
|
|
168
159
|
/**
|
|
169
160
|
* Head config
|
|
170
161
|
*
|
|
171
|
-
*
|
|
162
|
+
* Describe the tags to be appended into the `<head>` tag
|
|
172
163
|
*
|
|
173
164
|
* @default []
|
|
174
165
|
*
|
|
@@ -212,6 +203,11 @@ declare const ensureEndingSlash: (str: string) => string;
|
|
|
212
203
|
*/
|
|
213
204
|
declare const formatDateString: (str: string, defaultDateString?: string) => string;
|
|
214
205
|
|
|
206
|
+
/**
|
|
207
|
+
* Infer route path according to the given (markdown file) path
|
|
208
|
+
*/
|
|
209
|
+
declare const inferRoutePath: (path: string) => string;
|
|
210
|
+
|
|
215
211
|
/**
|
|
216
212
|
* Determine a link is external or not
|
|
217
213
|
*/
|
|
@@ -236,6 +232,11 @@ declare const isLinkWithProtocol: (link: string) => boolean;
|
|
|
236
232
|
*/
|
|
237
233
|
declare const isPlainObject: <T extends Record<any, any> = Record<any, any>>(val: unknown) => val is T;
|
|
238
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Normalize the given path to the final route path
|
|
237
|
+
*/
|
|
238
|
+
declare const normalizeRoutePath: (path: string, current?: string) => string;
|
|
239
|
+
|
|
239
240
|
/**
|
|
240
241
|
* Omit properties from an object
|
|
241
242
|
*/
|
|
@@ -254,7 +255,7 @@ declare const removeLeadingSlash: (str: string) => string;
|
|
|
254
255
|
/**
|
|
255
256
|
* Resolve identifier of a tag, to avoid duplicated tags in `<head>`
|
|
256
257
|
*/
|
|
257
|
-
declare const resolveHeadIdentifier: ([tag, attrs, content
|
|
258
|
+
declare const resolveHeadIdentifier: ([tag, attrs, content]: HeadConfig) => string | null;
|
|
258
259
|
|
|
259
260
|
/**
|
|
260
261
|
* Resolve the matched locale path of route path
|
|
@@ -263,4 +264,13 @@ declare const resolveLocalePath: (locales: LocaleConfig, routePath: string) => s
|
|
|
263
264
|
|
|
264
265
|
declare const resolveRoutePathFromUrl: (url: string, base?: string) => string;
|
|
265
266
|
|
|
266
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Check if a value is a function
|
|
269
|
+
*/
|
|
270
|
+
declare const isFunction: (val: unknown) => val is Function;
|
|
271
|
+
/**
|
|
272
|
+
* Check if a value is a string
|
|
273
|
+
*/
|
|
274
|
+
declare const isString: (val: unknown) => val is string;
|
|
275
|
+
|
|
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
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
// src/utils/index.ts
|
|
2
|
-
import { isArray, isFunction, isString } from "@vue/shared";
|
|
3
|
-
|
|
4
1
|
// src/utils/resolveHeadIdentifier.ts
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var TAGS_ALLOWED = ["link", "meta", "script", "style", "noscript", "template"];
|
|
3
|
+
var TAGS_UNIQUE = ["title", "base"];
|
|
4
|
+
var resolveHeadIdentifier = ([tag, attrs, content]) => {
|
|
5
|
+
if (TAGS_UNIQUE.includes(tag)) {
|
|
6
|
+
return tag;
|
|
7
|
+
}
|
|
8
|
+
if (!TAGS_ALLOWED.includes(tag)) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
10
11
|
if (tag === "meta" && attrs.name) {
|
|
11
12
|
return `${tag}.${attrs.name}`;
|
|
12
13
|
}
|
|
13
|
-
if (["title", "base"].includes(tag)) {
|
|
14
|
-
return tag;
|
|
15
|
-
}
|
|
16
14
|
if (tag === "template" && attrs.id) {
|
|
17
15
|
return `${tag}.${attrs.id}`;
|
|
18
16
|
}
|
|
19
|
-
return JSON.stringify([
|
|
17
|
+
return JSON.stringify([
|
|
18
|
+
tag,
|
|
19
|
+
Object.entries(attrs).map(([key, value]) => {
|
|
20
|
+
if (typeof value === "boolean") {
|
|
21
|
+
return value ? [key, ""] : null;
|
|
22
|
+
}
|
|
23
|
+
return [key, value];
|
|
24
|
+
}).filter((item) => item != null).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)),
|
|
25
|
+
content
|
|
26
|
+
]);
|
|
20
27
|
};
|
|
21
28
|
|
|
22
29
|
// src/utils/dedupeHead.ts
|
|
@@ -25,7 +32,7 @@ var dedupeHead = (head) => {
|
|
|
25
32
|
const result = [];
|
|
26
33
|
head.forEach((item) => {
|
|
27
34
|
const identifier = resolveHeadIdentifier(item);
|
|
28
|
-
if (!identifierSet.has(identifier)) {
|
|
35
|
+
if (identifier && !identifierSet.has(identifier)) {
|
|
29
36
|
identifierSet.add(identifier);
|
|
30
37
|
result.push(item);
|
|
31
38
|
}
|
|
@@ -49,27 +56,48 @@ var formatDateString = (str, defaultDateString = "") => {
|
|
|
49
56
|
return [yearStr, monthStr.padStart(2, "0"), dayStr.padStart(2, "0")].join("-");
|
|
50
57
|
};
|
|
51
58
|
|
|
52
|
-
// src/utils/
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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";
|
|
60
68
|
}
|
|
61
|
-
if (
|
|
62
|
-
|
|
69
|
+
if (routePath.endsWith("/index.html")) {
|
|
70
|
+
routePath = routePath.substring(0, routePath.length - 10);
|
|
63
71
|
}
|
|
64
|
-
return
|
|
72
|
+
return routePath;
|
|
65
73
|
};
|
|
66
74
|
|
|
67
75
|
// src/utils/isLinkWithProtocol.ts
|
|
68
|
-
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);
|
|
69
85
|
|
|
70
86
|
// src/utils/isPlainObject.ts
|
|
71
87
|
var isPlainObject = (val) => Object.prototype.toString.call(val) === "[object Object]";
|
|
72
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
|
+
|
|
73
101
|
// src/utils/omit.ts
|
|
74
102
|
var omit = (obj, ...keys) => {
|
|
75
103
|
const result = { ...obj };
|
|
@@ -104,21 +132,26 @@ var resolveLocalePath = (locales, routePath) => {
|
|
|
104
132
|
|
|
105
133
|
// src/utils/resolveRoutePathFromUrl.ts
|
|
106
134
|
var resolveRoutePathFromUrl = (url, base = "/") => {
|
|
107
|
-
const pathname = url.replace(/^(https?:)?\/\/[^/]*/, "");
|
|
135
|
+
const pathname = url.replace(/^(?:https?:)?\/\/[^/]*/, "");
|
|
108
136
|
return pathname.startsWith(base) ? `/${pathname.slice(base.length)}` : pathname;
|
|
109
137
|
};
|
|
138
|
+
|
|
139
|
+
// src/utils/typeGuards.ts
|
|
140
|
+
var isFunction = (val) => typeof val === "function";
|
|
141
|
+
var isString = (val) => typeof val === "string";
|
|
110
142
|
export {
|
|
111
143
|
dedupeHead,
|
|
112
144
|
ensureEndingSlash,
|
|
113
145
|
ensureLeadingSlash,
|
|
114
146
|
formatDateString,
|
|
115
|
-
|
|
147
|
+
inferRoutePath,
|
|
116
148
|
isFunction,
|
|
117
149
|
isLinkExternal,
|
|
118
150
|
isLinkHttp,
|
|
119
151
|
isLinkWithProtocol,
|
|
120
152
|
isPlainObject,
|
|
121
153
|
isString,
|
|
154
|
+
normalizeRoutePath,
|
|
122
155
|
omit,
|
|
123
156
|
removeEndingSlash,
|
|
124
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",
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
],
|
|
10
10
|
"homepage": "https://github.com/vuepress",
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/vuepress/
|
|
12
|
+
"url": "https://github.com/vuepress/core/issues"
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/vuepress/
|
|
16
|
+
"url": "git+https://github.com/vuepress/core.git"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"author": "meteorlxy",
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@mdit-vue/types": "^1.0
|
|
33
|
-
"@vue/shared": "^3.3.8"
|
|
32
|
+
"@mdit-vue/types": "^2.1.0"
|
|
34
33
|
},
|
|
35
34
|
"publishConfig": {
|
|
36
35
|
"access": "public"
|
|
@@ -47,7 +46,7 @@
|
|
|
47
46
|
"outDir": "./dist",
|
|
48
47
|
"sourcemap": false,
|
|
49
48
|
"target": "es2022",
|
|
50
|
-
"tsconfig": "
|
|
49
|
+
"tsconfig": "../../tsconfig.dts.json"
|
|
51
50
|
},
|
|
52
51
|
"scripts": {
|
|
53
52
|
"build": "tsup",
|