1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-08 02:26:14 +02:00

Update mdbook to 0.4.34 (#1066)

I also updated `book.js` and `index.hbs` to the latest versions while
keeping our local modifications.

I tested this locally with `mdbook serve` for both English and
Brazilian Portuguese and everything seems to work fine.
This commit is contained in:
Martin Geisler 2023-08-11 15:40:01 +02:00 committed by GitHub
parent e596b80c03
commit 2e92da7acd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 16 deletions

View File

@ -8,7 +8,7 @@ runs:
# The --locked flag is important for reproducible builds. It also # The --locked flag is important for reproducible builds. It also
# avoids breakage due to skews between mdbook and mdbook-svgbob. # avoids breakage due to skews between mdbook and mdbook-svgbob.
- name: Install mdbook - name: Install mdbook
run: cargo install mdbook --locked --version 0.4.28 run: cargo install mdbook --locked --version 0.4.34
shell: bash shell: bash
- name: Install mdbook-svgbob - name: Install mdbook-svgbob

View File

@ -64,6 +64,7 @@
{{/if}} {{/if}}
</head> </head>
<body> <body>
<div id="body-container">
<!-- Provide site root to javascript --> <!-- Provide site root to javascript -->
<script> <script>
var path_to_root = "{{ path_to_root }}"; var path_to_root = "{{ path_to_root }}";
@ -101,10 +102,12 @@
<!-- Hide / unhide sidebar before it is displayed --> <!-- Hide / unhide sidebar before it is displayed -->
<script> <script>
var html = document.querySelector('html'); var html = document.querySelector('html');
var sidebar = 'hidden'; var sidebar = null;
if (document.body.clientWidth >= 1080) { if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { } try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible'; sidebar = sidebar || 'visible';
} else {
sidebar = 'hidden';
} }
html.classList.remove('sidebar-visible'); html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar); html.classList.add("sidebar-" + sidebar);
@ -117,12 +120,34 @@
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div> <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
</nav> </nav>
<!-- Track and set sidebar scroll position -->
<script>
var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
sidebarScrollbox.addEventListener('click', function(e) {
if (e.target.tagName === 'A') {
sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
}
}, { passive: true });
var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
sessionStorage.removeItem('sidebar-scroll');
if (sidebarScrollTop) {
// preserve sidebar scroll position when navigating via links within sidebar
sidebarScrollbox.scrollTop = sidebarScrollTop;
} else {
// scroll sidebar to current active section when navigating via "next/previous chapter" buttons
var activeSection = document.querySelector('#sidebar .active');
if (activeSection) {
activeSection.scrollIntoView({ block: 'center' });
}
}
</script>
<div id="page-wrapper" class="page-wrapper"> <div id="page-wrapper" class="page-wrapper">
<div class="page"> <div class="page">
{{> header}} {{> header}}
<div id="menu-bar-hover-placeholder"></div> <div id="menu-bar-hover-placeholder"></div>
<div id="menu-bar" class="menu-bar sticky bordered"> <div id="menu-bar" class="menu-bar sticky">
<div class="left-buttons"> <div class="left-buttons">
<button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar"> <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i> <i class="fa fa-bars"></i>
@ -376,5 +401,6 @@
{{/if}} {{/if}}
{{/if}} {{/if}}
</div>
</body> </body>
</html> </html>

View File

@ -78,7 +78,7 @@ function playground_text(playground, hidden = true) {
} }
// updates the visibility of play button based on `no_run` class and // updates the visibility of play button based on `no_run` class and
// used crates vs ones available on http://play.rust-lang.org // used crates vs ones available on https://play.rust-lang.org
function update_play_button(pre_block, playground_crates) { function update_play_button(pre_block, playground_crates) {
var play_button = pre_block.querySelector(".play-button"); var play_button = pre_block.querySelector(".play-button");
@ -206,7 +206,7 @@ function playground_text(playground, hidden = true) {
// even if highlighting doesn't apply // even if highlighting doesn't apply
code_nodes.forEach(function (block) { block.classList.add('hljs'); }); code_nodes.forEach(function (block) { block.classList.add('hljs'); });
Array.from(document.querySelectorAll("code.language-rust")).forEach(function (block) { Array.from(document.querySelectorAll("code.hljs")).forEach(function (block) {
var lines = Array.from(block.querySelectorAll('.boring')); var lines = Array.from(block.querySelectorAll('.boring'));
// If no lines were hidden, return // If no lines were hidden, return
@ -373,7 +373,7 @@ function playground_text(playground, hidden = true) {
} }
setTimeout(function () { setTimeout(function () {
themeColorMetaTag.content = getComputedStyle(document.body).backgroundColor; themeColorMetaTag.content = getComputedStyle(document.documentElement).backgroundColor;
}, 1); }, 1);
if (window.ace && window.editors) { if (window.ace && window.editors) {
@ -578,13 +578,6 @@ function playground_text(playground, hidden = true) {
firstContact = null; firstContact = null;
} }
}, { passive: true }); }, { passive: true });
// Scroll sidebar to current active section
var activeSection = document.getElementById("sidebar").querySelector(".active");
if (activeSection) {
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
activeSection.scrollIntoView({ block: 'center' });
}
})(); })();
(function chapterNavigation() { (function chapterNavigation() {
@ -703,13 +696,14 @@ function playground_text(playground, hidden = true) {
}, { passive: true }); }, { passive: true });
})(); })();
(function controllBorder() { (function controllBorder() {
menu.classList.remove('bordered'); function updateBorder() {
document.addEventListener('scroll', function () {
if (menu.offsetTop === 0) { if (menu.offsetTop === 0) {
menu.classList.remove('bordered'); menu.classList.remove('bordered');
} else { } else {
menu.classList.add('bordered'); menu.classList.add('bordered');
} }
}, { passive: true }); }
updateBorder();
document.addEventListener('scroll', updateBorder, { passive: true });
})(); })();
})(); })();