dumi 2.1.0 → 2.1.1
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/features/routes.js
CHANGED
|
@@ -35,16 +35,19 @@ var CTX_LAYOUT_ID = "dumi-context-layout";
|
|
|
35
35
|
function normalizeDocDir(docDir) {
|
|
36
36
|
return typeof docDir === "object" ? docDir : { dir: docDir };
|
|
37
37
|
}
|
|
38
|
+
function kebabCaseRoutePath(routePath) {
|
|
39
|
+
return routePath.split("/").map((p) => import_plugin_utils.lodash.kebabCase(p)).join("/");
|
|
40
|
+
}
|
|
38
41
|
function localizeUmiRoute(route, locales) {
|
|
39
42
|
const locale = locales.find((locale2) => route.path.endsWith(`/${locale2.id}`) && import_path.default.parse(route.file).name.endsWith(`.${locale2.id}`));
|
|
40
43
|
if (locale) {
|
|
41
44
|
const base = !("base" in locale) || locale.base === "/" ? "" : locale.base.replace(/^(\/)(.+)$/, "$2$1");
|
|
42
45
|
const suffix = "suffix" in locale ? locale.suffix : "";
|
|
43
|
-
route.path = `${base}${route.path.replace(new RegExp(`/${locale.id}$`), "").replace(/((^|\/)(index|README))$/, "")
|
|
46
|
+
route.path = `${base}${kebabCaseRoutePath(route.path.replace(new RegExp(`/${locale.id}$`), "").replace(/((^|\/)(index|README))$/, ""))}${suffix}`;
|
|
44
47
|
route.absPath = route.path !== "/" ? `/${route.path}` : route.path;
|
|
45
48
|
} else {
|
|
46
|
-
route.path = route.path
|
|
47
|
-
route.absPath = route.absPath
|
|
49
|
+
route.path = kebabCaseRoutePath(route.path);
|
|
50
|
+
route.absPath = kebabCaseRoutePath(route.absPath);
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
function flatRoute(route, docLayoutId) {
|
|
@@ -53,10 +56,6 @@ function flatRoute(route, docLayoutId) {
|
|
|
53
56
|
route.path = route.path === "*" ? route.path : route.absPath.slice(1);
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
|
-
function kebabCaseRoute(route) {
|
|
57
|
-
route.path = route.path.split("/").map((p) => import_plugin_utils.lodash.kebabCase(p)).join("/");
|
|
58
|
-
route.absPath = route.absPath.split("/").map((p) => import_plugin_utils.lodash.kebabCase(p)).join("/");
|
|
59
|
-
}
|
|
60
59
|
function getClientPageFile(file, cwd) {
|
|
61
60
|
try {
|
|
62
61
|
return import_plugin_utils.resolve.sync(`dumi/dist/${file}`, {
|
|
@@ -168,7 +167,6 @@ var routes_default = (api) => {
|
|
|
168
167
|
throw new Error(`Invalid route path: ${route.path}, please rename it with only alphanumeric, dash and slash.
|
|
169
168
|
at ${route.file}`);
|
|
170
169
|
} else if (!route.isLayout) {
|
|
171
|
-
kebabCaseRoute(route);
|
|
172
170
|
flatRoute(route, docLayoutId);
|
|
173
171
|
localizeUmiRoute(route, api.config.locales);
|
|
174
172
|
}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
10
10
|
|
|
11
11
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
12
|
|
|
13
|
-
import { FormattedMessage, useIntl, usePrefersColor } from 'dumi';
|
|
13
|
+
import { FormattedMessage, useIntl, usePrefersColor, useSiteData } from 'dumi';
|
|
14
14
|
import React from 'react';
|
|
15
15
|
import "./index.less";
|
|
16
16
|
|
|
@@ -45,11 +45,15 @@ var ICON_MAPPING = {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
var ColorSwitch = function ColorSwitch() {
|
|
48
|
+
var _useSiteData = useSiteData(),
|
|
49
|
+
defaultColor = _useSiteData.themeConfig.prefersColor.default;
|
|
50
|
+
|
|
48
51
|
var intl = useIntl();
|
|
49
52
|
|
|
50
53
|
var _usePrefersColor = usePrefersColor(),
|
|
51
54
|
_usePrefersColor2 = _slicedToArray(_usePrefersColor, 3),
|
|
52
|
-
|
|
55
|
+
_usePrefersColor2$ = _usePrefersColor2[1],
|
|
56
|
+
prefersColor = _usePrefersColor2$ === void 0 ? defaultColor : _usePrefersColor2$,
|
|
53
57
|
setPrefersColor = _usePrefersColor2[2];
|
|
54
58
|
|
|
55
59
|
var Icon = ICON_MAPPING[prefersColor];
|
|
@@ -20,7 +20,9 @@ function getTargetLocalePath(_ref) {
|
|
|
20
20
|
current = _ref.current,
|
|
21
21
|
target = _ref.target;
|
|
22
22
|
var clearPath = 'base' in current ? pathname.replace(current.base.replace(/\/$/, ''), '') : pathname.replace(new RegExp("".concat(current.suffix, "$")), '');
|
|
23
|
-
return 'base' in target ? "".concat(
|
|
23
|
+
return 'base' in target ? "".concat( // for `/` base, strip duplicated leading slash
|
|
24
|
+
target.base.replace(/\/$/, '')).concat(clearPath) // for `/` clearPath, strip duplicated ending slash
|
|
25
|
+
.replace(/([^/])\/$/, '$1') : "".concat(clearPath).concat(target.suffix);
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
var SingleSwitch = function SingleSwitch(_ref2) {
|