Skip to content

Commit 4fcb02d

Browse files
committed
refactor: use nav items instead of strings
1 parent f88dc4c commit 4fcb02d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

docs/.vuepress/theme/components/Page.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,17 @@ export default {
6464
},
6565
htmlRouteClass: function () {
6666
// patch to apply a root class for styling elements
67+
// any path that isn't a primary nav item will add the route-index class
6768
const root = document.getElementsByTagName('html')[0]
68-
const parts = this.$page.path.split('/')
69-
const index = ['introduction', 'how-to', 'project', 'community']
70-
index.includes(parts[1])
71-
? root.classList.add('route-index')
72-
: root.classList.remove('route-index')
69+
const path = this.$page.path
70+
const navItems = this.$themeConfig.locales['/'].nav
71+
.slice(1)
72+
.map(a => a.link)
73+
navItems.some(i => path.includes(i))
74+
? root.classList.remove('route-index')
75+
: root.classList.add('route-index')
7376
}
7477
},
75-
7678
mounted: function () {
7779
this.smoothScroll()
7880
this.htmlRouteClass()

0 commit comments

Comments
 (0)