Skip to content

Commit 2abd4db

Browse files
committed
init
0 parents  commit 2abd4db

File tree

8 files changed

+209
-0
lines changed

8 files changed

+209
-0
lines changed

.github/workflows/pages.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: GH Pages Deploy
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
build-deploy:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
15+
- name: Install mdbook
16+
run: |
17+
mkdir bin
18+
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.43/mdbook-v0.4.43-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
19+
mv bin/mdbook ./
20+
rm -r bin'
21+
22+
- name: Install mdbook-pagetoc
23+
run: |
24+
mkdir bin
25+
curl -sSL https://github.com/slowsage/mdbook-pagetoc/releases/download/v0.2.0/mdbook-pagetoc-v0.2.0-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
26+
mv bin/mdbook-pagetoc ./
27+
rm -r bin'
28+
29+
- name: Build pages
30+
run: './mdbook build'
31+
32+
- name: Deploy to GitHub Pages
33+
if: ${{ github.event_name != 'pull_request' }}
34+
uses: peaceiris/actions-gh-pages@v3
35+
with:
36+
github_token: ${{ secrets.DEPLOY_GITHUB_TOKEN }}
37+
publish_dir: book

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
book

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Basalt Manual
2+
3+
This is the repo which hosts the source for the Basalt Manual.
4+
5+
To build, you must have both [mdBook](https://github.com/rust-lang/mdBook) and
6+
[mdBook-pagetoc](https://github.com/slowsage/mdbook-pagetoc) installed.
7+
8+
To build, you can run
9+
10+
```sh
11+
mdbook build
12+
```
13+
14+
To build the book into `book/`
15+
16+
For development, use
17+
18+
```sh
19+
mdbook serve [-p <port>]
20+
```
21+
22+
to build and serve (with hot reload) on a given port.

book.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[book]
2+
authors = ["basalt-rs"]
3+
language = "en"
4+
title = "Basalt Manual"
5+
description = "Manual for using basalt-rs and corrosponding tools"
6+
7+
[build]
8+
create-missing = false
9+
10+
[preprocessor.pagetoc]
11+
12+
[output.html]
13+
additional-css = ["theme/pagetoc.css"]
14+
additional-js = ["theme/pagetoc.js"]
15+
git-repository-url = "https://github.com/basalt-rs"
16+
17+
[output.html.print]
18+
enable = false

src/SUMMARY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Summary
2+
3+
---
4+
5+
- [Getting Started](./getting-started/index.md)

src/getting-started/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Getting Started

theme/pagetoc.css

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
@media only screen and (max-width:1439px) {
2+
.sidetoc {
3+
display: none;
4+
}
5+
}
6+
7+
@media only screen and (min-width:1440px) {
8+
main {
9+
position: relative;
10+
}
11+
.sidetoc {
12+
margin-left: auto;
13+
margin-right: auto;
14+
left: calc(100% + (var(--content-max-width))/4 - 140px);
15+
position: absolute;
16+
}
17+
.pagetoc {
18+
position: fixed;
19+
width: 200px;
20+
height: calc(100vh - var(--menu-bar-height) - 0.67em * 4);
21+
overflow: auto;
22+
}
23+
.pagetoc a {
24+
border-left: 1px solid var(--sidebar-bg);
25+
color: var(--fg) !important;
26+
display: block;
27+
padding-bottom: 5px;
28+
padding-top: 5px;
29+
padding-left: 10px;
30+
text-align: left;
31+
text-decoration: none;
32+
}
33+
.pagetoc a:hover,
34+
.pagetoc a.active {
35+
background: var(--sidebar-bg);
36+
color: var(--sidebar-fg) !important;
37+
}
38+
.pagetoc .active {
39+
background: var(--sidebar-bg);
40+
color: var(--sidebar-fg);
41+
}
42+
.pagetoc .pagetoc-H2 {
43+
padding-left: 20px;
44+
}
45+
.pagetoc .pagetoc-H3 {
46+
padding-left: 40px;
47+
}
48+
.pagetoc .pagetoc-H4 {
49+
padding-left: 60px;
50+
}
51+
.pagetoc .pagetoc-H5 {
52+
display: none;
53+
}
54+
.pagetoc .pagetoc-H6 {
55+
display: none;
56+
}
57+
}

theme/pagetoc.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
let scrollTimeout;
2+
3+
const listenActive = () => {
4+
const elems = document.querySelector(".pagetoc").children;
5+
[...elems].forEach(el => {
6+
el.addEventListener("click", (event) => {
7+
clearTimeout(scrollTimeout);
8+
[...elems].forEach(el => el.classList.remove("active"));
9+
el.classList.add("active");
10+
// Prevent scroll updates for a short period
11+
scrollTimeout = setTimeout(() => {
12+
scrollTimeout = null;
13+
}, 100); // Adjust timing as needed
14+
});
15+
});
16+
};
17+
18+
const getPagetoc = () => document.querySelector(".pagetoc") || autoCreatePagetoc();
19+
20+
const autoCreatePagetoc = () => {
21+
const main = document.querySelector("#content > main");
22+
const content = Object.assign(document.createElement("div"), {
23+
className: "content-wrap"
24+
});
25+
content.append(...main.childNodes);
26+
main.prepend(content);
27+
main.insertAdjacentHTML("afterbegin", '<div class="sidetoc"><nav class="pagetoc"></nav></div>');
28+
return document.querySelector(".pagetoc");
29+
};
30+
const updateFunction = () => {
31+
if (scrollTimeout) return; // Skip updates if within the cooldown period from a click
32+
const headers = [...document.getElementsByClassName("header")];
33+
const scrolledY = window.scrollY;
34+
let lastHeader = null;
35+
36+
// Find the last header that is above the current scroll position
37+
for (let i = headers.length - 1; i >= 0; i--) {
38+
if (scrolledY >= headers[i].offsetTop) {
39+
lastHeader = headers[i];
40+
break;
41+
}
42+
}
43+
44+
const pagetocLinks = [...document.querySelector(".pagetoc").children];
45+
pagetocLinks.forEach(link => link.classList.remove("active"));
46+
47+
if (lastHeader) {
48+
const activeLink = pagetocLinks.find(link => lastHeader.href === link.href);
49+
if (activeLink) activeLink.classList.add("active");
50+
}
51+
};
52+
53+
window.addEventListener('load', () => {
54+
const pagetoc = getPagetoc();
55+
const headers = [...document.getElementsByClassName("header")];
56+
headers.forEach(header => {
57+
const link = Object.assign(document.createElement("a"), {
58+
textContent: header.text,
59+
href: header.href,
60+
className: `pagetoc-${header.parentElement.tagName}`
61+
});
62+
pagetoc.appendChild(link);
63+
});
64+
updateFunction();
65+
listenActive();
66+
window.addEventListener("scroll", updateFunction);
67+
});
68+

0 commit comments

Comments
 (0)