Merge pull request #797 from h-enk/scroll-spy

🧪 Add scrollspy to toc pages as an option (experimental)
This commit is contained in:
Henk Verlinde 2022-07-05 11:37:00 +02:00 committed by GitHub
commit fdae102373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 3 deletions

View File

@ -571,6 +571,10 @@ $navbar-dark-active-color: $link-color-dark;
content: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='rgba%28222, 226, 230, 0.75%29' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M5 14l6-6-6-6'/%3e%3c/svg%3e"); content: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='rgba%28222, 226, 230, 0.75%29' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M5 14l6-6-6-6'/%3e%3c/svg%3e");
} }
[data-dark-mode] #toc a.active {
color: $link-color-dark;
}
[data-dark-mode] .btn-light { [data-dark-mode] .btn-light {
color: $link-color-dark; color: $link-color-dark;
background: $body-overlay-dark; background: $body-overlay-dark;

View File

@ -216,11 +216,17 @@ body {
text-decoration: none; text-decoration: none;
} }
#TableOfContents ul { #TableOfContents ul,
#toc ul {
padding-left: 0; padding-left: 0;
list-style: none; list-style: none;
} }
#toc a.active {
color: $primary;
font-weight: 500;
}
::selection { ::selection {
background: rgba(212, 53, 159, 0.2); background: rgba(212, 53, 159, 0.2);
} }

View File

@ -106,6 +106,7 @@ lastMod = false
fullWidth = false fullWidth = false
navbarSticky = true navbarSticky = true
toTopButton = false toTopButton = false
scrollSpy = false # experimental; needs Bootstrap >= 5.2.0-beta1
[menu] [menu]
[menu.section] [menu.section]

View File

@ -12,7 +12,7 @@
{{ .Scratch.Set "class" .Type -}} {{ .Scratch.Set "class" .Type -}}
{{ .Scratch.Add "class" " list" -}} {{ .Scratch.Add "class" " list" -}}
{{ end -}} {{ end -}}
<body class="{{ .Scratch.Get "class" }}"> <body class="{{ .Scratch.Get "class" }}"{{ if eq .Site.Params.options.scrollSpy true }} data-bs-spy="scroll" data-bs-target="#toc" data-bs-root-margin="0px 0px -90%" data-bs-smooth-scroll="true" tabindex="0"{{ end }}>
{{ partial "header/header.html" . }} {{ partial "header/header.html" . }}
<div class="wrap container-{{ if .Site.Params.options.fullWidth }}fluid{{ else }}xxl{{ end }}" role="document"> <div class="wrap container-{{ if .Site.Params.options.fullWidth }}fluid{{ else }}xxl{{ end }}" role="document">
<div class="content"> <div class="content">

View File

@ -17,6 +17,10 @@
</div> </div>
<div class="page-links d-none d-xl-block"> <div class="page-links d-none d-xl-block">
<h3>On this page</h3> <h3>On this page</h3>
{{ if eq .Site.Params.options.scrollSpy true -}}
{{ .TableOfContents | replaceRE "<nav id=\"TableOfContents\">" "<nav id=\"toc\">" | safeHTML }}
{{ else -}}
{{ .TableOfContents }} {{ .TableOfContents }}
{{ end -}}
</div> </div>
{{ end -}} {{ end -}}