Skip to content

Commit 8040157

Browse files
I HATE mdbook a bit
1 parent 6c1a6bc commit 8040157

File tree

2 files changed

+388
-0
lines changed

2 files changed

+388
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ and run `mdbook serve --open` in the project root. This will serve the book on
1414
Please see [the book](https://data101.dtek.se/contributing.html) for
1515
instructions on how to build and contribute to the project.
1616

17+
### Development
18+
19+
Now we come to the unfortunate reality that the mdbook container we use is out
20+
of date. In mdbook v0.4.46 they added a new function called `resource` which allows
21+
the book to actually build links properly when running mdbook locally. In
22+
versions before this we instead have to use a function called `path_to_root`
23+
which works great when building a docker image, but does not work great for
24+
local development. If you want to do a significant amount of development
25+
yourself we suggest replacing `theme/index.hbs` with `theme/development.hbs`
26+
while you're working. Do *NOT* commit this change because we need to use the
27+
current `index.hbs` version for docker builds. Yes this is very *very* annoying.
28+
Whenever `peaceiris/mdbook` gets updated to v0.4.46 or later we can actually
29+
replace this properly (we hope!).
30+
1731
## Compiling cheatsheets
1832

1933
To compile the cheatsheets, use `./typst_compile.sh`. Make sure to commit the

theme/development.hbs

Lines changed: 374 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,374 @@
1+
<!DOCTYPE HTML>
2+
<html lang="{{ language }}" class="{{ default_theme }} sidebar-visible" dir="{{ text_direction }}">
3+
<head>
4+
<!-- Book generated using mdBook -->
5+
<meta charset="UTF-8">
6+
<title>{{ title }}</title>
7+
{{#if is_print }}
8+
<meta name="robots" content="noindex">
9+
{{/if}}
10+
{{#if base_url}}
11+
<base href="{{ base_url }}">
12+
{{/if}}
13+
14+
15+
<!-- Custom HTML head -->
16+
{{> head}}
17+
18+
<meta name="description" content="{{ description }}">
19+
<meta name="viewport" content="width=device-width, initial-scale=1">
20+
<meta name="theme-color" content="#ffffff">
21+
22+
{{#if favicon_svg}}
23+
<link rel="icon" href="{{ resource "favicon.svg" }}">
24+
{{/if}}
25+
{{#if favicon_png}}
26+
<link rel="shortcut icon" href="{{ resource "favicon.png" }}">
27+
{{/if}}
28+
<link rel="stylesheet" href="{{ resource "css/variables.css" }}">
29+
<link rel="stylesheet" href="{{ resource "css/general.css" }}">
30+
<link rel="stylesheet" href="{{ resource "css/chrome.css" }}">
31+
{{#if print_enable}}
32+
<link rel="stylesheet" href="{{ resource "css/print.css" }}" media="print">
33+
{{/if}}
34+
35+
<!-- Fonts -->
36+
<link rel="stylesheet" href="{{ resource "FontAwesome/css/font-awesome.css" }}">
37+
{{#if copy_fonts}}
38+
<link rel="stylesheet" href="{{ resource "fonts/fonts.css" }}">
39+
{{/if}}
40+
41+
<!-- Highlight.js Stylesheets -->
42+
<link rel="stylesheet" id="highlight-css" href="{{ resource "highlight.css" }}">
43+
<link rel="stylesheet" id="tomorrow-night-css" href="{{ resource "tomorrow-night.css" }}">
44+
<link rel="stylesheet" id="ayu-highlight-css" href="{{ resource "ayu-highlight.css" }}">
45+
46+
<!-- Custom theme stylesheets -->
47+
{{#each additional_css}}
48+
<link rel="stylesheet" href="{{ resource this }}">
49+
{{/each}}
50+
51+
{{#if mathjax_support}}
52+
<!-- MathJax -->
53+
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
54+
{{/if}}
55+
56+
<!-- Provide site root and default themes to javascript -->
57+
<script>
58+
const path_to_root = "{{ path_to_root }}";
59+
const default_light_theme = "{{ default_theme }}";
60+
const default_dark_theme = "{{ preferred_dark_theme }}";
61+
</script>
62+
<!-- Start loading toc.js asap -->
63+
<script src="{{ resource "toc.js" }}"></script>
64+
</head>
65+
<body>
66+
67+
<!-- Work around some values being stored in localStorage wrapped in quotes -->
68+
<script>
69+
try {
70+
let theme = localStorage.getItem('mdbook-theme');
71+
let sidebar = localStorage.getItem('mdbook-sidebar');
72+
let os = localStorage.getItem("mdbook-os");
73+
74+
if (theme.startsWith('"') && theme.endsWith('"')) {
75+
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
76+
}
77+
78+
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
79+
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
80+
}
81+
82+
if (os.startsWith('"') && os.endsWith('"')) {
83+
localStorage.setItem('mdbook-os', os.slice(1, sidebar.length - 1));
84+
}
85+
} catch (e) { }
86+
</script>
87+
88+
<!-- Set the theme before any content is loaded, prevents flash -->
89+
<script>
90+
const default_theme = "{{ default_theme }}";
91+
let theme;
92+
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
93+
if (theme === null || theme === undefined) { theme = default_theme; }
94+
const html = document.documentElement;
95+
html.classList.remove('{{ default_theme }}')
96+
html.classList.add(theme);
97+
html.classList.add("js");
98+
</script>
99+
100+
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
101+
102+
<!-- Hide / unhide sidebar before it is displayed -->
103+
<script>
104+
let sidebar = null;
105+
const sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
106+
if (document.body.clientWidth >= 1080) {
107+
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
108+
sidebar = sidebar || 'visible';
109+
} else {
110+
sidebar = 'hidden';
111+
}
112+
sidebar_toggle.checked = sidebar === 'visible';
113+
html.classList.remove('sidebar-visible');
114+
html.classList.add("sidebar-" + sidebar);
115+
</script>
116+
117+
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
118+
<!-- populated by js -->
119+
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
120+
<noscript>
121+
<iframe class="sidebar-iframe-outer" src="{{ path_to_root }}toc.html"></iframe>
122+
</noscript>
123+
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
124+
<div class="sidebar-resize-indicator"></div>
125+
</div>
126+
</nav>
127+
128+
<div id="page-wrapper" class="page-wrapper">
129+
130+
<div class="page">
131+
{{> header}}
132+
<div id="menu-bar-hover-placeholder"></div>
133+
<div id="menu-bar" class="menu-bar sticky">
134+
<div class="left-buttons">
135+
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
136+
<i class="fa fa-bars"></i>
137+
</label>
138+
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
139+
<i class="fa fa-paint-brush"></i>
140+
</button>
141+
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
142+
<li role="none"><button role="menuitem" class="theme" id="tentaportalen">{{ theme_option "Tentaportalen" }}</button></li>
143+
<li role="none"><button role="menuitem" class="theme" id="light">{{ theme_option "Light" }}</button></li>
144+
<li role="none"><button role="menuitem" class="theme" id="navy">{{ theme_option "Navy" }}</button></li>
145+
</ul>
146+
<button id="os-toggle" class="icon-button" type="button" title="Change OS" aria-label="Change OS" aria-haspopup="true" aria-expanded="false" aria-controls="os-list">
147+
<i class="fa fa-windows"></i>
148+
</button>
149+
<ul id="os-list" class="theme-popup" aria-label="OS" role="menu">
150+
<li role="none"><button role="menuitem" class="theme" data-option="windows">Windows</button>
151+
</li>
152+
<li role="none"><button role="menuitem" class="theme" data-option="linux">Linux</button></li>
153+
<li role="none"><button role="menuitem" class="theme" data-option="macos">MacOS</button></li>
154+
<li role="none"><button role="menuitem" class="theme" data-option="all">Show all</button></li>
155+
</ul>
156+
<button id="programme-toggle" class="icon-button" type="button" title="Change Programme"
157+
aria-label="Change Programme" aria-haspopup="true" aria-expanded="false"
158+
aria-controls="programme-list">
159+
<span>All</span>
160+
</button>
161+
<ul id="programme-list" class="theme-popup" aria-label="Programme" role="menu">
162+
<li role="none"><button role="menuitem" class="theme" data-option="Data">Data</button></li>
163+
<li role="none"><button role="menuitem" class="theme" data-option="IT">IT</button></li>
164+
<li role="none"><button role="menuitem" class="theme" data-option="DV">DV</button></li>
165+
<li role="none"><button role="menuitem" class="theme" data-option="all">Show all</button></li>
166+
</ul>
167+
{{#if search_enabled}}
168+
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
169+
<i class="fa fa-search"></i>
170+
</button>
171+
{{/if}}
172+
</div>
173+
174+
<h1 class="menu-title">{{ book_title }}</h1>
175+
176+
<div class="right-buttons">
177+
{{#if print_enable}}
178+
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book">
179+
<i id="print-button" class="fa fa-print"></i>
180+
</a>
181+
{{/if}}
182+
{{#if git_repository_url}}
183+
<a href="{{git_repository_url}}" title="Git repository" aria-label="Git repository">
184+
<i id="git-repository-button" class="fa {{git_repository_icon}}"></i>
185+
</a>
186+
{{/if}}
187+
{{#if git_repository_edit_url}}
188+
<a href="{{git_repository_edit_url}}" title="Suggest an edit" aria-label="Suggest an edit">
189+
<i id="git-edit-button" class="fa fa-edit"></i>
190+
</a>
191+
{{/if}}
192+
193+
</div>
194+
</div>
195+
196+
{{#if search_enabled}}
197+
<div id="search-wrapper" class="hidden">
198+
<form id="searchbar-outer" class="searchbar-outer">
199+
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
200+
</form>
201+
<div id="searchresults-outer" class="searchresults-outer hidden">
202+
<div id="searchresults-header" class="searchresults-header"></div>
203+
<ul id="searchresults">
204+
</ul>
205+
</div>
206+
</div>
207+
{{/if}}
208+
209+
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
210+
<script>
211+
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
212+
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
213+
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
214+
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
215+
});
216+
</script>
217+
218+
<div id="content" class="content">
219+
<main>
220+
<blockquote id="alert-selection" class="danger hidden">
221+
<p>
222+
This book has specific content depending on your educational programme and operating system.
223+
Please select them in the bar above!
224+
</p>
225+
</blockquote>
226+
{{{ content }}}
227+
</main>
228+
229+
<nav class="nav-wrapper" aria-label="Page navigation">
230+
<!-- Mobile navigation buttons -->
231+
{{#previous}}
232+
<a rel="prev" href="{{ path_to_root }}{{link}}" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
233+
<i class="fa fa-angle-left"></i>
234+
</a>
235+
{{/previous}}
236+
237+
{{#next}}
238+
<a rel="next prefetch" href="{{ path_to_root }}{{link}}" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
239+
<i class="fa fa-angle-right"></i>
240+
</a>
241+
{{/next}}
242+
243+
<div style="clear: both"></div>
244+
</nav>
245+
</div>
246+
</div>
247+
248+
<nav class="nav-wide-wrapper" aria-label="Page navigation">
249+
{{#previous}}
250+
<a rel="prev" href="{{ path_to_root }}{{link}}" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
251+
<i class="fa fa-angle-left"></i>
252+
</a>
253+
{{/previous}}
254+
255+
{{#next}}
256+
<a rel="next prefetch" href="{{ path_to_root }}{{link}}" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
257+
<i class="fa fa-angle-right"></i>
258+
</a>
259+
{{/next}}
260+
</nav>
261+
262+
</div>
263+
264+
<div id="meta-prompt" class="prompt hidden">
265+
<div class="overlay"></div>
266+
<div class="modal">
267+
{{!-- <h3>Select programme and Operating system</h3> --}}
268+
<div class="cols">
269+
<div>
270+
<div class="title">Operating system</div>
271+
<div class="cols-select">
272+
<div class="relative icon" data-os="linux">
273+
<div class="fa fa-linux center"></div>
274+
</div>
275+
<div class="relative icon" data-os="macos">
276+
<div class="fa fa-apple center"></div>
277+
</div>
278+
<div class="relative icon" data-os="windows">
279+
<div class="fa fa-windows center"></div>
280+
</div>
281+
</div>
282+
</div>
283+
<div>
284+
<div class="title">Student division</div>
285+
<div class="cols-select">
286+
<div class="relative text-center text-data" data-programme="Data">
287+
Data
288+
</div>
289+
<div class="relative text-center text-it" data-programme="IT">
290+
IT
291+
</div>
292+
<div class="relative text-center text-dv" data-programme="DV">
293+
DV
294+
</div>
295+
</div>
296+
</div>
297+
</div>
298+
</div>
299+
</div>
300+
301+
{{#if live_reload_endpoint}}
302+
<!-- Livereload script (if served using the cli tool) -->
303+
<script>
304+
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
305+
const wsAddress = wsProtocol + "//" + location.host + "/" + "{{{live_reload_endpoint}}}";
306+
const socket = new WebSocket(wsAddress);
307+
socket.onmessage = function (event) {
308+
if (event.data === "reload") {
309+
socket.close();
310+
location.reload();
311+
}
312+
};
313+
314+
window.onbeforeunload = function() {
315+
socket.close();
316+
}
317+
</script>
318+
{{/if}}
319+
320+
{{#if playground_line_numbers}}
321+
<script>
322+
window.playground_line_numbers = true;
323+
</script>
324+
{{/if}}
325+
326+
{{#if playground_copyable}}
327+
<script>
328+
window.playground_copyable = true;
329+
</script>
330+
{{/if}}
331+
332+
{{#if playground_js}}
333+
<script src="{{ resource "ace.js" }}"></script>
334+
<script src="{{ resource "mode-rust.js" }}"></script>
335+
<script src="{{ resource "editor.js" }}"></script>
336+
<script src="{{ resource "theme-dawn.js" }}"></script>
337+
<script src="{{ resource "theme-tomorrow_night.js" }}"></script>
338+
{{/if}}
339+
340+
{{#if search_js}}
341+
<script src="{{ resource "elasticlunr.min.js" }}"></script>
342+
<script src="{{ resource "mark.min.js" }}"></script>
343+
<script src="{{ resource "searcher.js" }}"></script>
344+
{{/if}}
345+
346+
<script src="{{ resource "clipboard.min.js" }}"></script>
347+
<script src="{{ resource "highlight.js" }}"></script>
348+
<script src="{{ resource "book.js" }}"></script>
349+
350+
<!-- Custom JS scripts -->
351+
{{#each additional_js}}
352+
<script src="{{ resource this}}"></script>
353+
{{/each}}
354+
355+
{{#if is_print}}
356+
{{#if mathjax_support}}
357+
<script>
358+
window.addEventListener('load', function() {
359+
MathJax.Hub.Register.StartupHook('End', function() {
360+
window.setTimeout(window.print, 100);
361+
});
362+
});
363+
</script>
364+
{{else}}
365+
<script>
366+
window.addEventListener('load', function() {
367+
window.setTimeout(window.print, 100);
368+
});
369+
</script>
370+
{{/if}}
371+
{{/if}}
372+
373+
</body>
374+
</html>

0 commit comments

Comments
 (0)