Skip to content

Commit 9a025fe

Browse files
committed
update mdbook 0.4.43 assets
1 parent 760841b commit 9a025fe

27 files changed

+1000
-283
lines changed

.github/workflows/deploy-mdbook.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ jobs:
1515
toolchain: stable
1616
profile: minimal
1717
- name: Install mdBook
18-
# relative links are broken after v0.4.40, potentially because of https://github.com/rust-lang/mdBook/pull/2414
1918
run: |
20-
(test -x $HOME/.cargo/bin/mdbook || cargo install --vers "0.4.40" mdbook)
19+
(test -x $HOME/.cargo/bin/mdbook || cargo install --vers "^0.4" mdbook)
2120
cargo install mdbook-linkcheck mdbook-mermaid mdbook-admonish
2221
- name: Build and Test
2322
run: |

mdbook/book.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ command = "mdbook-mermaid"
2626

2727
[preprocessor.admonish]
2828
command = "mdbook-admonish"
29-
assets_version = "2.0.0" # do not edit: managed by `mdbook-admonish install`
29+
assets_version = "3.0.2" # do not edit: managed by `mdbook-admonish install`

mdbook/theme/.DS_Store

6 KB
Binary file not shown.

mdbook/theme/book.js

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
window.onunload = function () { };
55

66
// Global variable, shared between modules
7-
function playground_text(playground) {
7+
function playground_text(playground, hidden = true) {
88
let code_block = playground.querySelector("code");
99

1010
if (window.ace && code_block.classList.contains("editable")) {
1111
let editor = window.ace.edit(code_block);
1212
return editor.getValue();
13-
} else {
13+
} else if (hidden) {
1414
return code_block.textContent;
15+
} else {
16+
return code_block.innerText;
1517
}
1618
}
1719

@@ -66,7 +68,7 @@ function playground_text(playground) {
6668
}
6769

6870
// updates the visibility of play button based on `no_run` class and
69-
// used crates vs ones available on http://play.rust-lang.org
71+
// used crates vs ones available on https://play.rust-lang.org
7072
function update_play_button(pre_block, playground_crates) {
7173
var play_button = pre_block.querySelector(".play-button");
7274

@@ -166,7 +168,6 @@ function playground_text(playground) {
166168
.filter(function (node) {return node.classList.contains("editable"); })
167169
.forEach(function (block) { block.classList.remove('language-rust'); });
168170

169-
Array
170171
code_nodes
171172
.filter(function (node) {return !node.classList.contains("editable"); })
172173
.forEach(function (block) { hljs.highlightBlock(block); });
@@ -178,7 +179,7 @@ function playground_text(playground) {
178179
// even if highlighting doesn't apply
179180
code_nodes.forEach(function (block) { block.classList.add('hljs'); });
180181

181-
Array.from(document.querySelectorAll("code.language-rust")).forEach(function (block) {
182+
Array.from(document.querySelectorAll("code.hljs")).forEach(function (block) {
182183

183184
var lines = Array.from(block.querySelectorAll('.boring'));
184185
// If no lines were hidden, return
@@ -224,7 +225,7 @@ function playground_text(playground) {
224225
}
225226

226227
var clipButton = document.createElement('button');
227-
clipButton.className = 'fa fa-copy clip-button';
228+
clipButton.className = 'clip-button';
228229
clipButton.title = 'Copy to clipboard';
229230
clipButton.setAttribute('aria-label', clipButton.title);
230231
clipButton.innerHTML = '<i class=\"tooltiptext\"></i>';
@@ -257,7 +258,7 @@ function playground_text(playground) {
257258

258259
if (window.playground_copyable) {
259260
var copyCodeClipboardButton = document.createElement('button');
260-
copyCodeClipboardButton.className = 'fa fa-copy clip-button';
261+
copyCodeClipboardButton.className = 'clip-button';
261262
copyCodeClipboardButton.innerHTML = '<i class="tooltiptext"></i>';
262263
copyCodeClipboardButton.title = 'Copy to clipboard';
263264
copyCodeClipboardButton.setAttribute('aria-label', copyCodeClipboardButton.title);
@@ -288,6 +289,10 @@ function playground_text(playground) {
288289
var themeToggleButton = document.getElementById('theme-toggle');
289290
var themePopup = document.getElementById('theme-list');
290291
var themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
292+
var themeIds = [];
293+
themePopup.querySelectorAll('button.theme').forEach(function (el) {
294+
themeIds.push(el.id);
295+
});
291296
var stylesheets = {
292297
ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"),
293298
tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"),
@@ -300,6 +305,13 @@ function playground_text(playground) {
300305
themePopup.querySelector("button#" + get_theme()).focus();
301306
}
302307

308+
function updateThemeSelected() {
309+
themePopup.querySelectorAll('.theme-selected').forEach(function (el) {
310+
el.classList.remove('theme-selected');
311+
});
312+
themePopup.querySelector("button#" + get_theme()).classList.add('theme-selected');
313+
}
314+
303315
function hideThemes() {
304316
themePopup.style.display = 'none';
305317
themeToggleButton.setAttribute('aria-expanded', false);
@@ -309,7 +321,7 @@ function playground_text(playground) {
309321
function get_theme() {
310322
var theme;
311323
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
312-
if (theme === null || theme === undefined) {
324+
if (theme === null || theme === undefined || !themeIds.includes(theme)) {
313325
return default_theme;
314326
} else {
315327
return theme;
@@ -338,7 +350,7 @@ function playground_text(playground) {
338350
}
339351

340352
setTimeout(function () {
341-
themeColorMetaTag.content = getComputedStyle(document.body).backgroundColor;
353+
themeColorMetaTag.content = getComputedStyle(document.documentElement).backgroundColor;
342354
}, 1);
343355

344356
if (window.ace && window.editors) {
@@ -355,6 +367,7 @@ function playground_text(playground) {
355367

356368
html.classList.remove(previousTheme);
357369
html.classList.add(theme);
370+
updateThemeSelected();
358371
}
359372

360373
// Set theme
@@ -432,16 +445,16 @@ function playground_text(playground) {
432445
})();
433446

434447
(function sidebar() {
435-
var html = document.querySelector("html");
448+
var body = document.querySelector("body");
436449
var sidebar = document.getElementById("sidebar");
437450
var sidebarLinks = document.querySelectorAll('#sidebar a');
438451
var sidebarToggleButton = document.getElementById("sidebar-toggle");
439452
var sidebarResizeHandle = document.getElementById("sidebar-resize-handle");
440453
var firstContact = null;
441454

442455
function showSidebar() {
443-
html.classList.remove('sidebar-hidden')
444-
html.classList.add('sidebar-visible');
456+
body.classList.remove('sidebar-hidden')
457+
body.classList.add('sidebar-visible');
445458
Array.from(sidebarLinks).forEach(function (link) {
446459
link.setAttribute('tabIndex', 0);
447460
});
@@ -450,20 +463,9 @@ function playground_text(playground) {
450463
try { localStorage.setItem('mdbook-sidebar', 'visible'); } catch (e) { }
451464
}
452465

453-
454-
var sidebarAnchorToggles = document.querySelectorAll('#sidebar a.toggle');
455-
456-
function toggleSection(ev) {
457-
ev.currentTarget.parentElement.classList.toggle('expanded');
458-
}
459-
460-
Array.from(sidebarAnchorToggles).forEach(function (el) {
461-
el.addEventListener('click', toggleSection);
462-
});
463-
464466
function hideSidebar() {
465-
html.classList.remove('sidebar-visible')
466-
html.classList.add('sidebar-hidden');
467+
body.classList.remove('sidebar-visible')
468+
body.classList.add('sidebar-hidden');
467469
Array.from(sidebarLinks).forEach(function (link) {
468470
link.setAttribute('tabIndex', -1);
469471
});
@@ -474,14 +476,14 @@ function playground_text(playground) {
474476

475477
// Toggle sidebar
476478
sidebarToggleButton.addEventListener('click', function sidebarToggle() {
477-
if (html.classList.contains("sidebar-hidden")) {
479+
if (body.classList.contains("sidebar-hidden")) {
478480
var current_width = parseInt(
479481
document.documentElement.style.getPropertyValue('--sidebar-width'), 10);
480482
if (current_width < 150) {
481483
document.documentElement.style.setProperty('--sidebar-width', '150px');
482484
}
483485
showSidebar();
484-
} else if (html.classList.contains("sidebar-visible")) {
486+
} else if (body.classList.contains("sidebar-visible")) {
485487
hideSidebar();
486488
} else {
487489
if (getComputedStyle(sidebar)['transform'] === 'none') {
@@ -497,14 +499,14 @@ function playground_text(playground) {
497499
function initResize(e) {
498500
window.addEventListener('mousemove', resize, false);
499501
window.addEventListener('mouseup', stopResize, false);
500-
html.classList.add('sidebar-resizing');
502+
body.classList.add('sidebar-resizing');
501503
}
502504
function resize(e) {
503505
var pos = (e.clientX - sidebar.offsetLeft);
504506
if (pos < 20) {
505507
hideSidebar();
506508
} else {
507-
if (html.classList.contains("sidebar-hidden")) {
509+
if (body.classList.contains("sidebar-hidden")) {
508510
showSidebar();
509511
}
510512
pos = Math.min(pos, window.innerWidth - 100);
@@ -513,7 +515,7 @@ function playground_text(playground) {
513515
}
514516
//on mouseup remove windows functions mousemove & mouseup
515517
function stopResize(e) {
516-
html.classList.remove('sidebar-resizing');
518+
body.classList.remove('sidebar-resizing');
517519
window.removeEventListener('mousemove', resize, false);
518520
window.removeEventListener('mouseup', stopResize, false);
519521
}
@@ -542,33 +544,41 @@ function playground_text(playground) {
542544
firstContact = null;
543545
}
544546
}, { passive: true });
545-
546-
// Scroll sidebar to current active section
547-
var activeSection = document.getElementById("sidebar").querySelector(".active");
548-
if (activeSection) {
549-
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
550-
activeSection.scrollIntoView({ block: 'center' });
551-
}
552547
})();
553548

554549
(function chapterNavigation() {
555550
document.addEventListener('keydown', function (e) {
556551
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
557552
if (window.search && window.search.hasFocus()) { return; }
553+
var html = document.querySelector('html');
558554

555+
function next() {
556+
var nextButton = document.querySelector('.nav-chapters.next');
557+
if (nextButton) {
558+
window.location.href = nextButton.href;
559+
}
560+
}
561+
function prev() {
562+
var previousButton = document.querySelector('.nav-chapters.previous');
563+
if (previousButton) {
564+
window.location.href = previousButton.href;
565+
}
566+
}
559567
switch (e.key) {
560568
case 'ArrowRight':
561569
e.preventDefault();
562-
var nextButton = document.querySelector('.nav-chapters.next');
563-
if (nextButton) {
564-
window.location.href = nextButton.href;
570+
if (html.dir == 'rtl') {
571+
prev();
572+
} else {
573+
next();
565574
}
566575
break;
567576
case 'ArrowLeft':
568577
e.preventDefault();
569-
var previousButton = document.querySelector('.nav-chapters.previous');
570-
if (previousButton) {
571-
window.location.href = previousButton.href;
578+
if (html.dir == 'rtl') {
579+
next();
580+
} else {
581+
prev();
572582
}
573583
break;
574584
}
@@ -580,19 +590,19 @@ function playground_text(playground) {
580590

581591
function hideTooltip(elem) {
582592
elem.firstChild.innerText = "";
583-
elem.className = 'fa fa-copy clip-button';
593+
elem.className = 'clip-button';
584594
}
585595

586596
function showTooltip(elem, msg) {
587597
elem.firstChild.innerText = msg;
588-
elem.className = 'fa fa-copy tooltipped';
598+
elem.className = 'clip-button tooltipped';
589599
}
590600

591601
var clipboardSnippets = new ClipboardJS('.clip-button', {
592602
text: function (trigger) {
593603
hideTooltip(trigger);
594604
let playground = trigger.closest("pre");
595-
return playground_text(playground);
605+
return playground_text(playground, false);
596606
}
597607
});
598608

@@ -667,13 +677,14 @@ function playground_text(playground) {
667677
}, { passive: true });
668678
})();
669679
(function controllBorder() {
670-
menu.classList.remove('bordered');
671-
document.addEventListener('scroll', function () {
680+
function updateBorder() {
672681
if (menu.offsetTop === 0) {
673682
menu.classList.remove('bordered');
674683
} else {
675684
menu.classList.add('bordered');
676685
}
677-
}, { passive: true });
686+
}
687+
updateBorder();
688+
document.addEventListener('scroll', updateBorder, { passive: true });
678689
})();
679690
})();

0 commit comments

Comments
 (0)