From 1cf18fd850dbc75dd976406c20a2393e694d3bd0 Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Sun, 3 Feb 2019 21:54:07 +0800 Subject: [PATCH] feat: sidebarDepth for sidebar groups --- .../theme-default/components/Page.vue | 19 +++-- .../theme-default/components/Sidebar.vue | 68 ++-------------- .../theme-default/components/SidebarGroup.vue | 24 +++--- .../theme-default/components/SidebarLink.vue | 18 +++-- .../theme-default/components/SidebarLinks.vue | 79 +++++++++++++++++++ .../@vuepress/theme-default/util/index.js | 10 +-- packages/docs/docs/.vuepress/config.js | 24 +++++- 7 files changed, 146 insertions(+), 96 deletions(-) create mode 100644 packages/@vuepress/theme-default/components/SidebarLinks.vue diff --git a/packages/@vuepress/theme-default/components/Page.vue b/packages/@vuepress/theme-default/components/Page.vue index d086c0b8ba..c0d622a3ac 100644 --- a/packages/@vuepress/theme-default/components/Page.vue +++ b/packages/@vuepress/theme-default/components/Page.vue @@ -177,13 +177,7 @@ function resolveNext (page, items) { function find (page, items, offset) { const res = [] - items.forEach(item => { - if (item.type === 'group') { - res.push(...item.children || []) - } else { - res.push(item) - } - }) + flatternItems(items, res) for (let i = 0; i < res.length; i++) { const cur = res[i] if (cur.type === 'page' && cur.path === decodeURIComponent(page.path)) { @@ -191,6 +185,17 @@ function find (page, items, offset) { } } } + +function flatternItems (items, res) { + for (let i = 0, l = items.length; i < l; i++) { + if (items[i].type === 'group') { + flatternItems(items[i].children, res) + } else { + res.push(items[i]) + } + } +} +