Skip to content

Commit 6a96af0

Browse files
committed
fix(theme-default): fix error of sidebar resolving (close #185)
- resolve page headers for string sidebar item when the item is in the first level - resolve children of non-group sidebar item
1 parent 5c38968 commit 6a96af0

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

packages/@vuepress/theme-default/src/client/components/SidebarChild.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ const renderChildren = (
8989
export const SidebarChild: FunctionalComponent<{
9090
item: ResolvedSidebarItem
9191
depth?: number
92-
}> = ({ item, depth = 0 }) => {
92+
}> = ({
93+
item,
94+
// group depth should start from 0
95+
// otherwise start from 1
96+
depth = item.isGroup ? 0 : 1,
97+
}) => {
9398
const route = useRoute()
9499
const active = isActiveItem(route, item)
95100

@@ -134,6 +139,5 @@ SidebarChild.props = {
134139
depth: {
135140
type: Number,
136141
required: false,
137-
default: 0,
138142
},
139143
}

packages/@vuepress/theme-default/src/client/composables/useSidebarItems.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,16 @@ export const resolveArraySidebarItems = (
127127
childItem = item as ResolvedSidebarItem
128128
}
129129

130-
if (childItem.isGroup && childItem.children) {
130+
if (childItem.children) {
131131
return {
132132
...childItem,
133-
children: childItem.children.map(handleChildItem),
133+
children: childItem.children.map((item) => handleChildItem(item)),
134134
}
135135
}
136136

137137
// if the sidebar item is current page and children is not set
138138
// use headers of current page as children
139-
if (childItem.link === route.path && childItem.children === undefined) {
139+
if (childItem.link === route.path) {
140140
return {
141141
...childItem,
142142
children: headersToSidebarItemChildren(
@@ -149,21 +149,7 @@ export const resolveArraySidebarItems = (
149149
return childItem
150150
}
151151

152-
return sidebarConfig.map(
153-
(item): ResolvedSidebarItem => {
154-
if (isString(item)) {
155-
return useNavLink(item)
156-
}
157-
if (!item.isGroup) {
158-
return item as ResolvedSidebarItem
159-
}
160-
161-
return {
162-
...item,
163-
children: item.children.map(handleChildItem),
164-
}
165-
}
166-
)
152+
return sidebarConfig.map((item) => handleChildItem(item))
167153
}
168154

169155
/**

0 commit comments

Comments
 (0)