From 6ec8689130962cefa3d0cf648cd6629c16ff959a Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Thu, 24 Sep 2020 18:54:23 +0200 Subject: [PATCH] add support for children to page navigation --- docs/src/components/PageNavigation/index.vue | 28 +++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/docs/src/components/PageNavigation/index.vue b/docs/src/components/PageNavigation/index.vue index 4b0760b0..1590fbd1 100644 --- a/docs/src/components/PageNavigation/index.vue +++ b/docs/src/components/PageNavigation/index.vue @@ -38,18 +38,40 @@ export default { return this.linkGroups.reduce((acc, group) => ((acc.push(...group.items), acc)), []) }, + flattenedItems() { + const flattenedItems = [] + + this.items.forEach(({ title, link, items }) => { + flattenedItems.push({ + title, + link + }) + + if (items) { + items.forEach(({ title, link }) => { + flattenedItems.push({ + title, + link + }) + }) + } + }) + + return flattenedItems + }, + currentIndex() { - return this.items.findIndex(item => { + return this.flattenedItems.findIndex(item => { return item.link.replace(/\/$/, '') === this.$route.path.replace(/\/$/, '') }) }, nextPage() { - return this.items[this.currentIndex + 1] + return this.flattenedItems[this.currentIndex + 1] }, previousPage() { - return this.items[this.currentIndex - 1] + return this.flattenedItems[this.currentIndex - 1] }, }, }