dumi 2.2.13 → 2.2.14

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.
@@ -16,7 +16,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
16
16
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
17
  import { useFullSidebarData, useLocale, useSiteData } from 'dumi';
18
18
  import { useState } from 'react';
19
- import { getLocaleClearPath } from "./useSidebarData";
19
+ import { getLocaleClearPath, getRouteParentPath } from "./useSidebarData";
20
20
  import { getLocaleNav, pickRouteSortMeta, useLocaleDocRoutes, useRouteDataComparer } from "./utils";
21
21
  function genNavItem(meta, groups, activePath, link) {
22
22
  return _objectSpread({
@@ -70,11 +70,14 @@ export var useNavData = function useNavData() {
70
70
  var _ref6 = _slicedToArray(_ref5, 2),
71
71
  link = _ref6[0],
72
72
  groups = _ref6[1];
73
- var _ref7 = "/".concat(getLocaleClearPath(link.replace(/^\//, ''), locale)).match(/^(\/[^/]+)([^]+)?$/),
74
- _ref8 = _slicedToArray(_ref7, 3),
75
- parentPath = _ref8[1],
76
- restPath = _ref8[2];
77
- var isNestedNav = Boolean(restPath) && is2LevelNav;
73
+ var clearPath = getLocaleClearPath(link.replace(/^\//, ''), locale);
74
+ var parentPath = link.replace(clearPath, function (s) {
75
+ return getRouteParentPath(s, {
76
+ is2LevelNav: is2LevelNav,
77
+ locale: locale
78
+ });
79
+ });
80
+ var isNestedNav = link.length > parentPath.length && is2LevelNav;
78
81
  var _Object$values$reduce = Object.values(routes).reduce(function (ret, route) {
79
82
  // find routes which within the nav path
80
83
  if (route.path.startsWith(link.slice(1))) {
@@ -90,14 +93,14 @@ export var useNavData = function useNavData() {
90
93
  if (isNestedNav) {
91
94
  var _firstMeta$title, _ret$parentPath, _second$children;
92
95
  // fallback to use parent path as 1-level nav title
93
- (_firstMeta$title = firstMeta.title) !== null && _firstMeta$title !== void 0 ? _firstMeta$title : firstMeta.title = parentPath.slice(1).replace(/^[a-z]/, function (s) {
96
+ (_firstMeta$title = firstMeta.title) !== null && _firstMeta$title !== void 0 ? _firstMeta$title : firstMeta.title = parentPath.split('/').pop().replace(/^[a-z]/, function (s) {
94
97
  return s.toUpperCase();
95
98
  });
96
99
 
97
100
  // handle nested nav item as parent children
98
101
  var second = (_ret$parentPath = ret[parentPath]) !== null && _ret$parentPath !== void 0 ? _ret$parentPath : ret[parentPath] = genNavItem(firstMeta, groups, parentPath);
99
102
  (_second$children = second.children) !== null && _second$children !== void 0 ? _second$children : second.children = [];
100
- ret[parentPath].children.push(genNavItem(secondMeta, groups, link, groups[0].children[0].link));
103
+ second.children.push(genNavItem(secondMeta, groups, link, groups[0].children[0].link));
101
104
  } else {
102
105
  // handle root nav item
103
106
  ret[link] = genNavItem(firstMeta, groups, link, groups[0].children[0].link);
@@ -1,5 +1,13 @@
1
- import type { ILocalesConfig, ISidebarGroup } from './types';
1
+ import type { ILocalesConfig, IRouteMeta, ISidebarGroup } from './types';
2
2
  export declare const getLocaleClearPath: (routePath: string, locale: ILocalesConfig[0]) => string;
3
+ /**
4
+ * get parent path from route path
5
+ */
6
+ export declare function getRouteParentPath(path: string, { meta, is2LevelNav, locale, }: {
7
+ meta?: IRouteMeta;
8
+ is2LevelNav: boolean;
9
+ locale: ILocalesConfig[0];
10
+ }): string;
3
11
  /**
4
12
  * hook for get sidebar data for all nav
5
13
  */
@@ -26,11 +26,12 @@ export var getLocaleClearPath = function getLocaleClearPath(routePath, locale) {
26
26
  /**
27
27
  * get parent path from route path
28
28
  */
29
- function getRouteParentPath(path, _ref) {
30
- var _meta$frontmatter$fil;
29
+ export function getRouteParentPath(path, _ref) {
31
30
  var meta = _ref.meta,
32
- is2LevelNav = _ref.is2LevelNav;
33
- var isIndexDocRoute = ((_meta$frontmatter$fil = meta.frontmatter.filename) === null || _meta$frontmatter$fil === void 0 ? void 0 : _meta$frontmatter$fil.endsWith('index.md')) && !meta._atom_route && is2LevelNav;
31
+ is2LevelNav = _ref.is2LevelNav,
32
+ locale = _ref.locale;
33
+ var indexDocRegex = new RegExp("/index(\\.".concat(locale.id, ")?.md$"));
34
+ var isIndexDocRoute = (meta === null || meta === void 0 ? void 0 : meta.frontmatter.filename) && indexDocRegex.test(meta.frontmatter.filename) && !meta._atom_route && is2LevelNav;
34
35
  var paths = path.split('/')
35
36
  // strip end slash
36
37
  .filter(Boolean);
@@ -74,7 +75,8 @@ export var useFullSidebarData = function useFullSidebarData() {
74
75
  var parentPath = "/".concat(route.path.replace(clearPath, function (s) {
75
76
  return getRouteParentPath(s, {
76
77
  is2LevelNav: is2LevelNav,
77
- meta: route.meta
78
+ meta: route.meta,
79
+ locale: locale
78
80
  });
79
81
  }));
80
82
  var _pickRouteSortMeta = pickRouteSortMeta({
@@ -227,7 +229,8 @@ export var useSidebarData = function useSidebarData() {
227
229
  var parentPath = clearPath ? pathname.replace(clearPath, function (s) {
228
230
  return getRouteParentPath(s, {
229
231
  is2LevelNav: is2LevelNav,
230
- meta: meta
232
+ meta: meta,
233
+ locale: locale
231
234
  });
232
235
  }) : pathname;
233
236
  return parentPath ? sidebar[parentPath] : [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.2.13",
3
+ "version": "2.2.14",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",