Skip to content

Commit

Permalink
upd: docs files
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Jan 4, 2024
1 parent 5f8c68d commit e821d53
Show file tree
Hide file tree
Showing 8 changed files with 486 additions and 15 deletions.
5 changes: 2 additions & 3 deletions docs/.gitignore
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
6 changes: 6 additions & 0 deletions docs/README.md
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.
4 changes: 1 addition & 3 deletions docs/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ multilingual = false
src = "src"
title = "devshell"

[preprocessor.pagetoc]

[output.html]
# Show github links in top bar
git-repository-url = "https://github.com/numtide/devshell"
edit-url-template = "https://github.com/numtide/devshell/edit/main/docs/{path}"
additional-css = ["theme/pagetoc.css", "theme/pagetoc-tweaks.css"]
additional-css = ["theme/pagetoc.css"]
additional-js = ["theme/pagetoc.js"]
4 changes: 0 additions & 4 deletions docs/serve.sh

This file was deleted.

351 changes: 351 additions & 0 deletions docs/theme/index.hbs

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions docs/theme/pagetoc-tweaks.css

This file was deleted.

72 changes: 72 additions & 0 deletions docs/theme/pagetoc.css
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;
}
}
54 changes: 54 additions & 0 deletions docs/theme/pagetoc.js
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);

0 comments on commit e821d53

Please sign in to comment.