add mermaid.js support
This commit is contained in:
parent
441fb82411
commit
0442390142
|
@ -15,15 +15,11 @@ jobs:
|
|||
fetch-depth: 0
|
||||
- name: Install latest mdbook
|
||||
run: |
|
||||
apt-get update -qq
|
||||
apt-get install -qq jq
|
||||
tag="$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name')"
|
||||
url="https://github.com/rust-lang/mdbook/releases/download/${tag}/mdbook-${tag}-x86_64-unknown-linux-gnu.tar.gz"
|
||||
mkdir mdbook
|
||||
curl -sSL "$url" | tar -xz --directory=./mdbook
|
||||
echo "`pwd`"/mdbook >> $GITHUB_PATH
|
||||
scripts/install_deps.sh
|
||||
echo "`pwd`"/bin >> $GITHUB_PATH
|
||||
- name: Build Book
|
||||
run: |
|
||||
mdbook-mermaid install .
|
||||
mdbook build
|
||||
- name: Push to rendered branch
|
||||
run: |
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
|||
book
|
||||
/*.tar.gz
|
||||
/mermaid.min.js
|
|
@ -11,6 +11,9 @@ edition = "2021"
|
|||
|
||||
[preprocessor.links]
|
||||
|
||||
[preprocessor.mermaid]
|
||||
command = "mdbook-mermaid"
|
||||
|
||||
[output.html]
|
||||
mathjax-support = true
|
||||
no-section-label = true
|
||||
|
@ -19,6 +22,7 @@ git-repository-icon = "fa-git"
|
|||
# edit-url-template = "https://git.libre-chip.org/libre-chip/website/FIXME/{path}"
|
||||
input-404 = "404.md"
|
||||
additional-css = ["src/custom.css"]
|
||||
additional-js = ["mermaid.min.js", "mermaid-init.js"]
|
||||
|
||||
[output.html.print]
|
||||
enable = false
|
35
mermaid-init.js
Normal file
35
mermaid-init.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
(() => {
|
||||
const darkThemes = ['ayu', 'navy', 'coal'];
|
||||
const lightThemes = ['light', 'rust'];
|
||||
|
||||
const classList = document.getElementsByTagName('html')[0].classList;
|
||||
|
||||
let lastThemeWasLight = true;
|
||||
for (const cssClass of classList) {
|
||||
if (darkThemes.includes(cssClass)) {
|
||||
lastThemeWasLight = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const theme = lastThemeWasLight ? 'default' : 'dark';
|
||||
mermaid.initialize({ startOnLoad: true, theme });
|
||||
|
||||
// Simplest way to make mermaid re-render the diagrams in the new theme is via refreshing the page
|
||||
|
||||
for (const darkTheme of darkThemes) {
|
||||
document.getElementById(darkTheme).addEventListener('click', () => {
|
||||
if (lastThemeWasLight) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (const lightTheme of lightThemes) {
|
||||
document.getElementById(lightTheme).addEventListener('click', () => {
|
||||
if (!lastThemeWasLight) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
12
scripts/install_deps.sh
Executable file
12
scripts/install_deps.sh
Executable file
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
curl -sSL -o mdbook.tar.gz https://github.com/rust-lang/mdBook/releases/download/v0.4.40/mdbook-v0.4.40-x86_64-unknown-linux-gnu.tar.gz
|
||||
curl -sSL -o mdbook-mermaid.tar.gz https://github.com/badboy/mdbook-mermaid/releases/download/v0.14.0/mdbook-mermaid-v0.14.0-x86_64-unknown-linux-gnu.tar.gz
|
||||
sha256sum -c <<EOF
|
||||
37364965fb190cf9929d93c930c6b6c69b2fed05f7658ea2d312882ed59c645e mdbook-mermaid.tar.gz
|
||||
9ef07fd288ba58ff3b99d1c94e6d414d431c9a61fdb20348e5beb74b823d546b mdbook.tar.gz
|
||||
EOF
|
||||
mkdir -p bin
|
||||
echo "*" > bin/.gitignore
|
||||
tar -xz --directory=./bin -f mdbook.tar.gz
|
||||
tar -xz --directory=./bin -f mdbook-mermaid.tar.gz
|
Loading…
Reference in a new issue