Skip to content

Commit 15edc91

Browse files
authored
Enable "you are here" table of contents highlighting (#716)
* enable bootstrap scrollspy Signed-off-by: Pete Lumbis <[email protected]> * enable bootstrap scrollspy Signed-off-by: Pete Lumbis <[email protected]> * add TOC editing to enable scrollspy styling Signed-off-by: Pete Lumbis <[email protected]> * move TOC generation to a partial and inject bootstrap scrollspy styling Signed-off-by: Pete Lumbis <[email protected]> * set scrollspy margin offset Signed-off-by: Pete Lumbis <[email protected]> --------- Signed-off-by: Pete Lumbis <[email protected]>
1 parent e055eaa commit 15edc91

File tree

9 files changed

+59
-9
lines changed

9 files changed

+59
-9
lines changed

themes/geekboot/assets/js/main-41e2db8f.bundle.min.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

themes/geekboot/assets/js/main-41e2db8f.bundle.min.js renamed to themes/geekboot/assets/js/main-727bf178.bundle.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

themes/geekboot/assets/js/main-727bf178.bundle.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

themes/geekboot/assets/scss/_toc.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
padding-left: 0;
2121
margin-bottom: 0;
2222
list-style: none;
23+
display: inherit;
24+
2325

2426
ul {
2527
padding-left: 1rem;
2628
margin-top: .25rem;
2729
}
30+
2831
}
2932

3033
li {
@@ -33,11 +36,29 @@
3336

3437
a {
3538
color: inherit;
39+
display: inherit;
40+
padding: inherit;
41+
42+
&.active {
43+
color: var(--content-link-color);
44+
font-weight: 600;
45+
letter-spacing: .60px;
46+
47+
&:hover{
48+
color: var(--content-link-color);;
49+
text-decoration: underline !important;
50+
}
51+
}
3652

3753
&:not(:hover) {
3854
text-decoration: none;
3955
}
4056

57+
&:hover{
58+
color: inherit;
59+
text-decoration: underline !important;
60+
}
61+
4162
code {
4263
font: inherit;
4364
}

themes/geekboot/data/assets.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"main.js": {
3-
"src": "js/main-41e2db8f.bundle.min.js"
3+
"src": "js/main-727bf178.bundle.min.js"
44
},
5-
"main-41e2db8f.bundle.min.js.map": {
6-
"src": "js/main-41e2db8f.bundle.min.js.map"
5+
"main-727bf178.bundle.min.js.map": {
6+
"src": "js/main-727bf178.bundle.min.js.map"
77
}
88
}

themes/geekboot/layouts/partials/single-list.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="bd-layout docs-container">
1+
<div class="bd-layout docs-container" data-bs-spy="scroll" data-bs-target="#TableOfContents" data-bs-threshold="0,1" data-bs-root-margin="0% 0% -75%">
22
<aside class="bd-sidebar">
33
<div class="offcanvas-lg offcanvas-start bd-sidebar-container" tabindex="-1" id="bdSidebar" aria-labelledby="bdSidebarOffcanvasLabel">
44
<div class="offcanvas-header pb-4 border-bottom">
@@ -49,7 +49,7 @@ <h1 class="bd-title mb-0" id="content">{{ .Title | markdownify }}
4949
<strong class="d-none d-md-block h6 my-2">On this page</strong>
5050
<hr class="d-none d-md-block my-2">
5151
<div class="collapse bd-toc-collapse" id="tocContents">
52-
{{ .TableOfContents }}
52+
{{ partial "toc" .}}
5353
<nav class="pt-3">
5454
<div class="pb-2">
5555
<svg class="bi" width="1em" height="1em"><use xlink:href="#pencil-square"/></svg>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
{{/*
3+
The Hugo TOC function can't be changed gracefully.
4+
This edits the HTML output from the TOC function to add Bootstrap Nav classes.
5+
6+
The multiple variable chaining is for readablity.
7+
*/}}
8+
9+
{{/* The H1 element isn't in the TOC. Remove the extra <ul><li> Hugo generates */}}
10+
{{ $topNavFix := replaceRE `(\<nav id="TableOfContents"\>\s*\<ul\>\s*\<li\>)` "<nav id=\"TableOfContents\">" .TableOfContents }}
11+
12+
13+
{{/* Remove the extra closing <li><ul> */}}
14+
{{ $bottomNavFix := replaceRE `(\<\/li\>s*\<\/ul\>\s*\<\/nav\>)` "</nav>" $topNavFix }}
15+
16+
{{/* Add class="nav" to each <ul> element */}}
17+
{{$ulFix := replace $bottomNavFix "<ul>" "<ul class=\"nav\">" }}
18+
19+
20+
{{/* Add class="nav-item" to each <li> element */}}
21+
{{$liFix := replace $ulFix "<li" "<li class=\"nav-item\"" }}
22+
23+
24+
{{/* Add class="nav-link" to each <a> element */}}
25+
{{ $linkFix := replace $liFix "<a href" "<a class=\"nav-link\" href" }}
26+
27+
{{/* Print the new ToC and tell Hugo to render it instead of printing HTML */}}
28+
{{ $linkFix | safeHTML }}

utils/webpack/src/js/globalScripts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import './bootstrap/src/button';
88
import './bootstrap/src/collapse';
99
import './bootstrap/src/dropdown';
1010
import './bootstrap/src/popover';
11+
import './bootstrap/src/scrollspy';
1112
import './bootstrap/src/tab';
1213
import './bootstrap/src/offcanvas';
1314

0 commit comments

Comments
 (0)