Skip to content

Commit

Permalink
fix: nav title cannot work in singe 2-level directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou-Bill committed May 16, 2024
1 parent dbe6542 commit a132c4f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions examples/normal/docs/a/b/c.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
nav:
title: 'nav title'
second:
title: 'second title'
---

doc/a/b/c.md
8 changes: 8 additions & 0 deletions examples/normal/docs/a/b/d.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
nav:
title: 'nav title'
second:
title: 'second title2'
---

doc/a/b/d.md
7 changes: 6 additions & 1 deletion src/client/theme-api/useNavData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,14 @@ export const useNavData = () => {
);

data.forEach((item, i) => {
// item.link => the parent link is not in routes, but has children, will use parent.title or children.title
if (!item.link && item.children?.length === 1) {
// hoist nav item if only one child
data[i] = item.children[0];
const first = item.children[0];
data[i] = {
...first,
title: item?.title || first.title,
};
} else if (item.children) {
// sort nav item children by order or title
item.children.sort(sidebarDataComparer);
Expand Down

0 comments on commit a132c4f

Please sign in to comment.