Skip to content

Commit e1d1f2c

Browse files
authored
Merge pull request #1897 from ehuss/fix-theme
Update mdbook theme for newer version
2 parents 90a8b26 + 1174efc commit e1d1f2c

File tree

2 files changed

+19
-38
lines changed

2 files changed

+19
-38
lines changed

.github/workflows/rbe.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Install mdbook
2828
run: |
2929
mkdir bin
30-
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.37/mdbook-v0.4.37-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
30+
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.42/mdbook-v0.4.42-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
3131
echo "$(pwd)/bin" >> ${GITHUB_PATH}
3232
3333
- name: Install mdbook-i18n-helpers

theme/index.hbs

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE HTML>
2-
<html lang="{{ language }}" class="{{ default_theme }}" dir="{{ text_direction }}">
2+
<html lang="{{ language }}" class="{{ default_theme }} sidebar-visible" dir="{{ text_direction }}">
33
<head>
44
<!-- Book generated using mdBook -->
55
<meta charset="UTF-8">
@@ -52,15 +52,17 @@
5252
<!-- MathJax -->
5353
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
5454
{{/if}}
55-
</head>
56-
<body class="sidebar-visible no-js">
57-
<div id="body-container">
55+
5856
<!-- Provide site root to javascript -->
5957
<script>
6058
var path_to_root = "{{ path_to_root }}";
6159
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "{{ preferred_dark_theme }}" : "{{ default_theme }}";
6260
</script>
63-
61+
<!-- Start loading toc.js asap -->
62+
<script src="{{ path_to_root }}toc.js"></script>
63+
</head>
64+
<body>
65+
<div id="body-container">
6466
<!-- Work around some values being stored in localStorage wrapped in quotes -->
6567
<script>
6668
try {
@@ -82,19 +84,16 @@
8284
var theme;
8385
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
8486
if (theme === null || theme === undefined) { theme = default_theme; }
85-
var html = document.querySelector('html');
87+
const html = document.documentElement;
8688
html.classList.remove('{{ default_theme }}')
8789
html.classList.add(theme);
88-
var body = document.querySelector('body');
89-
body.classList.remove('no-js')
90-
body.classList.add('js');
90+
html.classList.add("js");
9191
</script>
9292

9393
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
9494

9595
<!-- Hide / unhide sidebar before it is displayed -->
9696
<script>
97-
var body = document.querySelector('body');
9897
var sidebar = null;
9998
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
10099
if (document.body.clientWidth >= 1080) {
@@ -104,39 +103,21 @@
104103
sidebar = 'hidden';
105104
}
106105
sidebar_toggle.checked = sidebar === 'visible';
107-
body.classList.remove('sidebar-visible');
108-
body.classList.add("sidebar-" + sidebar);
106+
html.classList.remove('sidebar-visible');
107+
html.classList.add("sidebar-" + sidebar);
109108
</script>
110109

111110
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
112-
<div class="sidebar-scrollbox">
113-
{{#toc}}{{/toc}}
111+
<!-- populated by js -->
112+
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
113+
<noscript>
114+
<iframe class="sidebar-iframe-outer" src="{{ path_to_root }}toc.html"></iframe>
115+
</noscript>
116+
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
117+
<div class="sidebar-resize-indicator"></div>
114118
</div>
115-
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
116119
</nav>
117120

118-
<!-- Track and set sidebar scroll position -->
119-
<script>
120-
var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
121-
sidebarScrollbox.addEventListener('click', function(e) {
122-
if (e.target.tagName === 'A') {
123-
sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
124-
}
125-
}, { passive: true });
126-
var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
127-
sessionStorage.removeItem('sidebar-scroll');
128-
if (sidebarScrollTop) {
129-
// preserve sidebar scroll position when navigating via links within sidebar
130-
sidebarScrollbox.scrollTop = sidebarScrollTop;
131-
} else {
132-
// scroll sidebar to current active section when navigating via "next/previous chapter" buttons
133-
var activeSection = document.querySelector('#sidebar .active');
134-
if (activeSection) {
135-
activeSection.scrollIntoView({ block: 'center' });
136-
}
137-
}
138-
</script>
139-
140121
<div id="page-wrapper" class="page-wrapper">
141122

142123
<div class="page">

0 commit comments

Comments
 (0)