Skip to content

Commit f88dc4c

Browse files
committed
apply root class element
1 parent 3a9bce5 commit f88dc4c

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,30 @@ export default {
5656
},
5757
methods: {
5858
smoothScroll: function () {
59-
var root = document.getElementsByTagName('html')[0]
59+
const root = document.getElementsByTagName('html')[0]
6060
// only enable smooth-scrolling on pages shorter that 15000 px
6161
return root.scrollHeight < 15000
6262
? root.classList.add('smooth-scroll')
6363
: root.classList.remove('smooth-scroll')
64+
},
65+
htmlRouteClass: function () {
66+
// patch to apply a root class for styling elements
67+
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')
6473
}
6574
},
75+
6676
mounted: function () {
6777
this.smoothScroll()
78+
this.htmlRouteClass()
6879
},
6980
updated: function () {
7081
this.smoothScroll()
82+
this.htmlRouteClass()
7183
}
7284
}
7385
</script>

docs/.vuepress/theme/styles/sidebar.styl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ header.navbar .nav-links {
6767
}
6868
}
6969

70+
// style selected sidebar item based on route class
71+
html.route-index {
72+
.sidebar .nav-links .nav-item:first-child {
73+
a.nav-link {
74+
color: $accentColor;
75+
}
76+
}
77+
}
78+
7079
@media (min-width: $MQMobile) {
7180
aside.sidebar {
7281
display: flex;
@@ -100,10 +109,6 @@ header.navbar .nav-links {
100109

101110
.nav-links, .nav-links a {
102111
display: block;
103-
104-
&:hover, &.router-link-active {
105-
color: $textColor;
106-
}
107112
}
108113

109114
.nav-item > a:not(.external) {

0 commit comments

Comments
 (0)