Skip to content

Commit

Permalink
add mermaid stack diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Dec 12, 2024
1 parent a93efe2 commit edd168a
Show file tree
Hide file tree
Showing 6 changed files with 2,499 additions and 29 deletions.
6 changes: 6 additions & 0 deletions docs/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ src = "src"
title = "Shotover"

[output.html]
additional-js = ["mermaid.min.js", "mermaid-init.js"]

[output.linkcheck]
# Should we check links on the internet? Enabling this option adds a
# non-negligible performance impact
follow-web-links = false

warning-policy = "error"

[preprocessor]

[preprocessor.mermaid]
command = "mdbook-mermaid"
35 changes: 35 additions & 0 deletions docs/mermaid-init.js
Original file line number Diff line number Diff line change
@@ -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();
}
});
}
})();
2,186 changes: 2,186 additions & 0 deletions docs/mermaid.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit edd168a

Please sign in to comment.