Skip to content

Commit af6dff5

Browse files
update to mdbook-0.4.44 and sync book.js and index.hbs (#2610)
mdbook in CI pipeline is updated to mdbook-0.4.44 - reran mdbook init --theme - keep playground improvements - keep language selector and suggest edit / edit to translation button text - improvement: toc is in separate js file, makes html file way smaller - additionally updated to mdbook-i18n-helpers-0.3.5 relevant upstream changes that are used: - rust-lang/mdBook#2414 - rust-lang/mdBook#2421 - rust-lang/mdBook#2454 - rust-lang/mdBook#2463
1 parent f1459c5 commit af6dff5

File tree

3 files changed

+31
-64
lines changed

3 files changed

+31
-64
lines changed

install-mdbook.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22
# The --locked flag is important for reproducible builds. It also
33
# avoids breakage due to skews between mdbook and mdbook-svgbob.
4-
cargo install mdbook --locked --version 0.4.37
4+
cargo install mdbook --locked --version 0.4.44
55
cargo install mdbook-svgbob --locked --version 0.2.1
66
cargo install mdbook-pandoc --locked --version 0.9.3
7-
cargo install mdbook-i18n-helpers --locked --version 0.3.3
7+
cargo install mdbook-i18n-helpers --locked --version 0.3.5
88
cargo install i18n-report --locked --version 0.2.0
99
# these packages are located in this repository
1010
cargo install --path mdbook-exerciser --locked

theme/book.js

+13-25
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ function playground_text(playground, hidden = true) {
290290
}
291291

292292
var clipButton = document.createElement('button');
293-
clipButton.className = 'fa fa-copy clip-button';
293+
clipButton.className = 'clip-button';
294294
clipButton.title = 'Copy to clipboard';
295295
clipButton.setAttribute('aria-label', clipButton.title);
296296
clipButton.innerHTML = '<i class=\"tooltiptext\"></i>';
@@ -323,7 +323,7 @@ function playground_text(playground, hidden = true) {
323323

324324
if (window.playground_copyable) {
325325
var copyCodeClipboardButton = document.createElement('button');
326-
copyCodeClipboardButton.className = 'fa fa-copy clip-button';
326+
copyCodeClipboardButton.className = 'clip-button';
327327
copyCodeClipboardButton.innerHTML = '<i class="tooltiptext"></i>';
328328
copyCodeClipboardButton.title = 'Copy to clipboard';
329329
copyCodeClipboardButton.setAttribute('aria-label', copyCodeClipboardButton.title);
@@ -354,6 +354,10 @@ function playground_text(playground, hidden = true) {
354354
var themeToggleButton = document.getElementById('theme-toggle');
355355
var themePopup = document.getElementById('theme-list');
356356
var themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
357+
var themeIds = [];
358+
themePopup.querySelectorAll('button.theme').forEach(function (el) {
359+
themeIds.push(el.id);
360+
});
357361
var stylesheets = {
358362
ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"),
359363
tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"),
@@ -382,7 +386,7 @@ function playground_text(playground, hidden = true) {
382386
function get_theme() {
383387
var theme;
384388
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
385-
if (theme === null || theme === undefined) {
389+
if (theme === null || theme === undefined || !themeIds.includes(theme)) {
386390
return default_theme;
387391
} else {
388392
return theme;
@@ -510,6 +514,7 @@ function playground_text(playground, hidden = true) {
510514
var sidebar = document.getElementById("sidebar");
511515
var sidebarLinks = document.querySelectorAll('#sidebar a');
512516
var sidebarToggleButton = document.getElementById("sidebar-toggle");
517+
var sidebarToggleAnchor = document.getElementById("sidebar-toggle-anchor");
513518
var sidebarResizeHandle = document.getElementById("sidebar-resize-handle");
514519
var firstContact = null;
515520

@@ -524,17 +529,6 @@ function playground_text(playground, hidden = true) {
524529
try { localStorage.setItem('mdbook-sidebar', 'visible'); } catch (e) { }
525530
}
526531

527-
528-
var sidebarAnchorToggles = document.querySelectorAll('#sidebar a.toggle');
529-
530-
function toggleSection(ev) {
531-
ev.currentTarget.parentElement.classList.toggle('expanded');
532-
}
533-
534-
Array.from(sidebarAnchorToggles).forEach(function (el) {
535-
el.addEventListener('click', toggleSection);
536-
});
537-
538532
function hideSidebar() {
539533
body.classList.remove('sidebar-visible')
540534
body.classList.add('sidebar-hidden');
@@ -547,22 +541,16 @@ function playground_text(playground, hidden = true) {
547541
}
548542

549543
// Toggle sidebar
550-
sidebarToggleButton.addEventListener('click', function sidebarToggle() {
551-
if (body.classList.contains("sidebar-hidden")) {
544+
sidebarToggleAnchor.addEventListener('change', function sidebarToggle() {
545+
if (sidebarToggleAnchor.checked) {
552546
var current_width = parseInt(
553547
document.documentElement.style.getPropertyValue('--sidebar-width'), 10);
554548
if (current_width < 150) {
555549
document.documentElement.style.setProperty('--sidebar-width', '150px');
556550
}
557551
showSidebar();
558-
} else if (body.classList.contains("sidebar-visible")) {
559-
hideSidebar();
560552
} else {
561-
if (getComputedStyle(sidebar)['transform'] === 'none') {
562-
hideSidebar();
563-
} else {
564-
showSidebar();
565-
}
553+
hideSidebar();
566554
}
567555
});
568556

@@ -662,12 +650,12 @@ function playground_text(playground, hidden = true) {
662650

663651
function hideTooltip(elem) {
664652
elem.firstChild.innerText = "";
665-
elem.className = 'fa fa-copy clip-button';
653+
elem.className = 'clip-button';
666654
}
667655

668656
function showTooltip(elem, msg) {
669657
elem.firstChild.innerText = msg;
670-
elem.className = 'fa fa-copy tooltipped';
658+
elem.className = 'clip-button tooltipped';
671659
}
672660

673661
var clipboardSnippets = new ClipboardJS('.clip-button', {

theme/index.hbs

+16-37
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,41 +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}}
114-
</div>
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>
115116
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
116117
<div class="sidebar-resize-indicator"></div>
117118
</div>
118119
</nav>
119120

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

144123
<div class="page">

0 commit comments

Comments
 (0)