dumi 2.0.0-rc.7 → 2.0.0-rc.8
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 +16 -16
- package/package.json +1 -1
package/dist/features/routes.js
CHANGED
|
@@ -44,10 +44,10 @@ function localizeUmiRoute(route, locales) {
|
|
|
44
44
|
route.absPath = route.path !== "/" ? `/${route.path}` : route.path;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
function flatRoute(route) {
|
|
48
|
-
if (route.parentId !==
|
|
49
|
-
route.parentId =
|
|
50
|
-
route.path = route.path === "*" ? route.path
|
|
47
|
+
function flatRoute(route, docLayoutId) {
|
|
48
|
+
if (route.parentId !== docLayoutId) {
|
|
49
|
+
route.parentId = docLayoutId;
|
|
50
|
+
route.path = route.path === "*" ? route.path : route.absPath.slice(1);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
function getClientPageFile(file, cwd) {
|
|
@@ -121,8 +121,6 @@ var routes_default = (api) => {
|
|
|
121
121
|
}
|
|
122
122
|
Object.entries(pages).forEach(([, route]) => {
|
|
123
123
|
route.file = (0, import_plugin_utils.winPath)(import_path.default.resolve(api.config.conventionRoutes.base, route.file));
|
|
124
|
-
flatRoute(route);
|
|
125
|
-
localizeUmiRoute(route, api.config.locales);
|
|
126
124
|
routes[route.id] = route;
|
|
127
125
|
});
|
|
128
126
|
docDirs.map(normalizeDocDir).forEach(({ type, dir }) => {
|
|
@@ -133,14 +131,12 @@ var routes_default = (api) => {
|
|
|
133
131
|
});
|
|
134
132
|
Object.entries(dirRoutes).forEach(([key, route]) => {
|
|
135
133
|
route.id = `${dir}/${key}`;
|
|
136
|
-
flatRoute(route);
|
|
137
134
|
if (type) {
|
|
138
135
|
const pluralType = (0, import_pluralize.plural)(type);
|
|
139
136
|
route.path = `${pluralType}/${route.path}`.replace(/\/+$/, "/");
|
|
140
137
|
route.absPath = `/${route.path}`;
|
|
141
138
|
}
|
|
142
139
|
route.file = (0, import_plugin_utils.winPath)(import_path.default.resolve(base, route.file));
|
|
143
|
-
localizeUmiRoute(route, api.config.locales);
|
|
144
140
|
routes[route.id] = route;
|
|
145
141
|
});
|
|
146
142
|
});
|
|
@@ -148,7 +144,7 @@ var routes_default = (api) => {
|
|
|
148
144
|
const base = import_path.default.join(api.cwd, dir);
|
|
149
145
|
const atomFiles = import_plugin_utils.glob.sync("{*,*/index,*/index.*,*/README,*/README.*}.md", { cwd: base });
|
|
150
146
|
atomFiles.forEach((file) => {
|
|
151
|
-
const routePath = (0, import_plugin_utils.winPath)(import_path.default.join((0, import_pluralize.plural)(type), file)).replace(/(\/index|\/README)?\.md$/, "").replace(/\./g, "/")
|
|
147
|
+
const routePath = (0, import_plugin_utils.winPath)(import_path.default.join((0, import_pluralize.plural)(type), file)).replace(/(\/index|\/README)?\.md$/, "").replace(/\./g, "/");
|
|
152
148
|
const routeId = (0, import_utils.createRouteId)(file);
|
|
153
149
|
routes[routeId] = {
|
|
154
150
|
id: routeId,
|
|
@@ -157,9 +153,19 @@ var routes_default = (api) => {
|
|
|
157
153
|
parentId: docLayoutId,
|
|
158
154
|
file: (0, import_plugin_utils.winPath)(import_path.default.resolve(base, file))
|
|
159
155
|
};
|
|
160
|
-
localizeUmiRoute(routes[routeId], api.config.locales);
|
|
161
156
|
});
|
|
162
157
|
});
|
|
158
|
+
Object.values(routes).forEach((route) => {
|
|
159
|
+
if (route.path !== encodeURI(route.path)) {
|
|
160
|
+
throw new Error(`Invalid route path: ${route.path}, please rename it with only alphanumeric, dash and slash.
|
|
161
|
+
at ${route.file}`);
|
|
162
|
+
} else if (!route.isLayout) {
|
|
163
|
+
flatRoute(route, docLayoutId);
|
|
164
|
+
localizeUmiRoute(route, api.config.locales);
|
|
165
|
+
route.path = route.path.toLowerCase();
|
|
166
|
+
route.absPath = route.absPath.toLowerCase();
|
|
167
|
+
}
|
|
168
|
+
});
|
|
163
169
|
if (Object.values(pages).every((route) => route.path !== "*")) {
|
|
164
170
|
routes["404"] = {
|
|
165
171
|
id: "404",
|
|
@@ -176,12 +182,6 @@ var routes_default = (api) => {
|
|
|
176
182
|
parentId: demoLayoutId,
|
|
177
183
|
file: getClientPageFile("client/pages/Demo", api.cwd)
|
|
178
184
|
};
|
|
179
|
-
Object.values(routes).forEach((route) => {
|
|
180
|
-
if (route.path !== encodeURI(route.path)) {
|
|
181
|
-
throw new Error(`Invalid route path: ${route.path}, please rename it with only alphanumeric, dash and slash.
|
|
182
|
-
at ${route.file}`);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
185
|
return routes;
|
|
186
186
|
});
|
|
187
187
|
api.addLayouts(() => {
|