Skip to content

Commit

Permalink
feat: 增加移除空分组配置
Browse files Browse the repository at this point in the history
  • Loading branch information
shanyuhai123 committed Mar 29, 2022
1 parent dcb7b8a commit b6abdb2
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/vuepress-docs-test/docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
mode: "titlecase",
map: {
"/menu1/menu1-2/": "修改个标题",
"/menu2/menu2-2/": "中间分组"
"/menu2/menu2-2/": "中间分组",
"/menu1/menu1-1/": "分组666",
}
},
sidebarDepth: 1,
Expand All @@ -26,7 +27,8 @@ module.exports = {
menu: "/menu3/menu3-3/",
regex: "ignore-*"
}
]
],
removeEmptyGroup: true
}
},
themeConfig: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: file1-1-1
autoGroup-1: 分组1
---

Hello File 1-1-1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: file1-1-2
autoPrev: File1-1-3
autoGroup-1: 分组1
---

Hello File 1-1-2
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: file1-1-3
autoGroup-2: 分组2
---

Hello File 1-1-3
1 change: 1 addition & 0 deletions packages/vuepress-docs-test/docs/menu1/menu1-1/Readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: file1-1
autoGroup-2: 分组2
---

Hello File 1-1
2 changes: 2 additions & 0 deletions packages/vuepress-plugin-auto-sidebar/src/config/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const AutoSidebarOptionsDefault: AutoSidebarPluginOptions = {
uncollapseList: [] // 不折叠列表
},
ignore: [],
// 移除空分组
removeEmptyGroup: false,
git: {
trackStatus: 'all' // 是否忽略未跟踪的文件
}
Expand Down
1 change: 1 addition & 0 deletions packages/vuepress-plugin-auto-sidebar/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface AutoSidebarPluginOptions {
sidebarDepth: number
collapse: CollapseOptions
ignore: IgnoreOptions
removeEmptyGroup: Boolean
git: GitOptions
}

Expand Down
8 changes: 8 additions & 0 deletions packages/vuepress-plugin-auto-sidebar/src/utils/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,13 @@ export const genSidebar = (sortedGroupPages: GroupPagesResult, options: AutoSide
...below.map(b => genGroup(b.groupName, b.children, collapsable, options.sidebarDepth))
]

if (options.removeEmptyGroup) {
acc[group].forEach((g, idx) => {
if (g.children.length === 0) {
acc[group].splice(idx, 1)
}
})
}

return acc
}, {})

0 comments on commit b6abdb2

Please sign in to comment.