vitepress-plugin-toolkit 0.6.0 → 0.7.0
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.
|
@@ -49,7 +49,7 @@ function isExternal(path) {
|
|
|
49
49
|
* URL_PROTOCOL_RE.test('mailto:foo@example.com') // true
|
|
50
50
|
* URL_PROTOCOL_RE.test('//cdn.example.com/lib.js') // false
|
|
51
51
|
*/
|
|
52
|
-
const URL_PROTOCOL_RE = /^[a-z][a-z0-9+.-]
|
|
52
|
+
const URL_PROTOCOL_RE = /^[a-z][a-z0-9+.-]*:/i;
|
|
53
53
|
/**
|
|
54
54
|
* Checks whether the given link contains a URL protocol scheme or is a
|
|
55
55
|
* protocol-relative URL.
|
package/dist/client/ssr/index.js
CHANGED
|
@@ -50,7 +50,7 @@ function isExternal(path) {
|
|
|
50
50
|
* URL_PROTOCOL_RE.test('mailto:foo@example.com') // true
|
|
51
51
|
* URL_PROTOCOL_RE.test('//cdn.example.com/lib.js') // false
|
|
52
52
|
*/
|
|
53
|
-
const URL_PROTOCOL_RE = /^[a-z][a-z0-9+.-]
|
|
53
|
+
const URL_PROTOCOL_RE = /^[a-z][a-z0-9+.-]*:/i;
|
|
54
54
|
/**
|
|
55
55
|
* Checks whether the given link contains a URL protocol scheme or is a
|
|
56
56
|
* protocol-relative URL.
|
package/dist/node/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import container from "markdown-it-container";
|
|
2
|
-
import { LRUCache, camelCase, deepMerge, isArray, isBoolean, isNull, isNumber, isPrimitive, isString, isUndefined, kebabCase, objectEntries, objectKeys, omit, removeTrailingSlash, slash, toArray, uniq } from "@pengzhanbo/utils";
|
|
2
|
+
import { LRUCache, attempt, camelCase, deepMerge, isArray, isBoolean, isNull, isNumber, isPrimitive, isString, isUndefined, kebabCase, objectEntries, objectKeys, omit, removeTrailingSlash, slash, toArray, uniq } from "@pengzhanbo/utils";
|
|
3
3
|
import ansis from "ansis";
|
|
4
4
|
import process from "node:process";
|
|
5
5
|
import picomatch from "picomatch";
|
|
@@ -53,7 +53,7 @@ function isExternal(path) {
|
|
|
53
53
|
* URL_PROTOCOL_RE.test('mailto:foo@example.com') // true
|
|
54
54
|
* URL_PROTOCOL_RE.test('//cdn.example.com/lib.js') // false
|
|
55
55
|
*/
|
|
56
|
-
const URL_PROTOCOL_RE = /^[a-z][a-z0-9+.-]
|
|
56
|
+
const URL_PROTOCOL_RE = /^[a-z][a-z0-9+.-]*:/i;
|
|
57
57
|
/**
|
|
58
58
|
* Checks whether the given link contains a URL protocol scheme or is a
|
|
59
59
|
* protocol-relative URL.
|
|
@@ -495,7 +495,7 @@ function resolveMatcherPattern(include, exclude) {
|
|
|
495
495
|
};
|
|
496
496
|
}
|
|
497
497
|
function normalize(arr) {
|
|
498
|
-
return isArray(arr) ? arr.sort((a, b) => a.localeCompare(b)) : arr;
|
|
498
|
+
return isArray(arr) ? [...arr].sort((a, b) => a.localeCompare(b)) : arr;
|
|
499
499
|
}
|
|
500
500
|
//#endregion
|
|
501
501
|
//#region src/node/utils/logger.ts
|
|
@@ -576,6 +576,7 @@ function createLogger(prefix, defaultLevel = "info") {
|
|
|
576
576
|
* ```
|
|
577
577
|
*/
|
|
578
578
|
function parseRect(str, unit = "px") {
|
|
579
|
+
str = str.trim();
|
|
579
580
|
if (Number.parseFloat(str) === Number(str)) return `${str}${unit}`;
|
|
580
581
|
return str;
|
|
581
582
|
}
|
|
@@ -830,7 +831,7 @@ function createLocales(builtinLocales, userLocales = {}) {
|
|
|
830
831
|
locales[key] = localeData;
|
|
831
832
|
break;
|
|
832
833
|
}
|
|
833
|
-
if (!locales.root) locales.root = builtinLocales[0][1];
|
|
834
|
+
if (!locales.root) locales.root = builtinLocales[0]?.[1] || {};
|
|
834
835
|
deepMerge(locales, userLocales);
|
|
835
836
|
return locales;
|
|
836
837
|
}
|
|
@@ -859,7 +860,7 @@ function createLocales(builtinLocales, userLocales = {}) {
|
|
|
859
860
|
*/
|
|
860
861
|
function getLocaleWithPath(path) {
|
|
861
862
|
const locales = getVitepressConfig().userConfig?.locales || {};
|
|
862
|
-
const keys = objectKeys(locales);
|
|
863
|
+
const keys = objectKeys(locales).sort((a, b) => b.length - a.length);
|
|
863
864
|
const key = keys.find((locale) => path.startsWith(locale)) || keys[0] || "";
|
|
864
865
|
if (!key || !locales[key]) return {
|
|
865
866
|
lang: "",
|
|
@@ -907,9 +908,11 @@ function resolveRouteLink(url, env) {
|
|
|
907
908
|
if (isExternal(url)) return url;
|
|
908
909
|
const config = getVitepressConfig();
|
|
909
910
|
if (url.startsWith("/")) return slash(removeTrailingSlash(config.site.base) + url);
|
|
910
|
-
if (url.startsWith("#")) return
|
|
911
|
-
const
|
|
912
|
-
if (
|
|
911
|
+
if (url.startsWith("#")) return normalizeHash(url);
|
|
912
|
+
const [error, data] = attempt(() => new URL(url, "http://a.com"));
|
|
913
|
+
if (error) return url;
|
|
914
|
+
const { pathname, protocol } = data;
|
|
915
|
+
if (protocol.startsWith("http") && treatAsHtml(pathname)) {
|
|
913
916
|
const indexMatch = url.match(indexRE);
|
|
914
917
|
if (indexMatch) {
|
|
915
918
|
const [, path, hash] = indexMatch;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitepress-plugin-toolkit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"description": "Development toolkit for vitepress plugins",
|
|
6
6
|
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo/)",
|
|
7
7
|
"license": "MIT",
|