-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
486 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
theme/* | ||
!theme/pagetoc-tweaks.css | ||
book | ||
book | ||
src/modules_schema.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# docs | ||
|
||
## Table of contents | ||
|
||
- The [theme/pagetoc.css](./theme/pagetoc.css) and [theme/pagetoc.js](./theme/pagetoc.js) files were adopted from [mdbook-pagetoc](https://github.com/slowsage/mdbook-pagetoc) with minor modifications. | ||
- The [theme/index.hbs](./theme/index.hbs) file was adopted from [mdBook](https://github.com/rust-lang/mdBook) with minor modifications. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* Adopted from https://github.com/slowsage/mdbook-pagetoc */ | ||
|
||
:root { | ||
--sidebar-width: 23rem; | ||
} | ||
|
||
a[class^="pagetoc-H"]:only-child { | ||
display: none; | ||
} | ||
|
||
.nav-chapters { | ||
margin-left: 15px; | ||
min-width: 50px; | ||
} | ||
|
||
@media only screen and (max-width:1511px) { | ||
.sidetoc { | ||
display: none; | ||
} | ||
} | ||
|
||
@media only screen and (min-width:1512px) { | ||
main { | ||
position: relative; | ||
} | ||
.sidetoc { | ||
margin-left: auto; | ||
margin-right: auto; | ||
left: calc(100% + (var(--content-max-width))/4 - 140px); | ||
position: absolute; | ||
} | ||
.pagetoc { | ||
position: fixed; | ||
width: 280px; | ||
height: calc(100vh - var(--menu-bar-height) - 0.67em * 4); | ||
overflow: auto; | ||
} | ||
.pagetoc a { | ||
border-left: 1px solid var(--sidebar-bg); | ||
color: var(--fg) !important; | ||
display: block; | ||
padding-bottom: 5px; | ||
padding-top: 5px; | ||
padding-left: 10px; | ||
text-align: left; | ||
text-decoration: none; | ||
} | ||
.pagetoc a:hover, | ||
.pagetoc a.active { | ||
background: var(--sidebar-bg); | ||
color: var(--sidebar-fg) !important; | ||
} | ||
.pagetoc .active { | ||
background: var(--sidebar-bg); | ||
color: var(--sidebar-fg); | ||
} | ||
.pagetoc .pagetoc-H2 { | ||
padding-left: 20px; | ||
} | ||
.pagetoc .pagetoc-H3 { | ||
padding-left: 40px; | ||
} | ||
.pagetoc .pagetoc-H4 { | ||
padding-left: 60px; | ||
} | ||
.pagetoc .pagetoc-H5 { | ||
display: none; | ||
} | ||
.pagetoc .pagetoc-H6 { | ||
display: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
var forEach = function (elems, fun) { | ||
Array.prototype.forEach.call(elems, fun); | ||
}; | ||
|
||
// Un-active everything when you click it | ||
var forPagetocElem = function (fun) { | ||
forEach(document.getElementsByClassName("pagetoc")[0].children, fun); | ||
}; | ||
|
||
forPagetocElem(function (el) { | ||
el.addEventHandler("click", function () { | ||
forPagetocElem(function (el) { | ||
el.classList.remove("active"); | ||
}); | ||
el.classList.add("active"); | ||
}); | ||
}); | ||
|
||
var updateFunction = function () { | ||
var id; | ||
var elements = document.getElementsByClassName("header"); | ||
forEach(elements, function (el) { | ||
if (window.scrollY >= el.offsetTop) { | ||
id = el; | ||
} | ||
}); | ||
|
||
forPagetocElem(function (el) { | ||
el.classList.remove("active"); | ||
}); | ||
if (!id) return; | ||
forPagetocElem(function (el) { | ||
if (id.href.localeCompare(el.href) == 0) { | ||
el.classList.add("active"); | ||
} | ||
}); | ||
}; | ||
|
||
// Populate sidebar on load | ||
window.addEventListener("load", function () { | ||
var pagetoc = document.getElementsByClassName("pagetoc")[0]; | ||
var elements = document.getElementsByClassName("header"); | ||
forEach(elements, function (el) { | ||
var link = document.createElement("a"); | ||
link.appendChild(document.createTextNode(el.text)); | ||
link.href = el.href; | ||
link.classList.add("pagetoc-" + el.parentElement.tagName); | ||
pagetoc.appendChild(link); | ||
}); | ||
updateFunction.call(); | ||
}); | ||
|
||
// Handle active elements on scroll | ||
window.addEventListener("scroll", updateFunction); |