From 64b9734354c4902f4ddc69681626e7d8570510d8 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 8 Mar 2025 16:15:12 -0800 Subject: [PATCH] Update mdbook to 0.4.46 --- .github/workflows/rbe.yml | 2 +- book.toml | 2 + theme/head.hbs | 4 + theme/index.hbs | 376 ------------------------------------ theme/js/language-picker.js | 50 +++++ 5 files changed, 57 insertions(+), 377 deletions(-) create mode 100644 theme/head.hbs delete mode 100644 theme/index.hbs create mode 100644 theme/js/language-picker.js diff --git a/.github/workflows/rbe.yml b/.github/workflows/rbe.yml index 97b7c0bc79..b482285d8a 100644 --- a/.github/workflows/rbe.yml +++ b/.github/workflows/rbe.yml @@ -27,7 +27,7 @@ jobs: - name: Install mdbook run: | mkdir bin - 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 + curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.46/mdbook-v0.4.46-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin echo "$(pwd)/bin" >> ${GITHUB_PATH} - name: Install mdbook-i18n-helpers diff --git a/book.toml b/book.toml index e8364161b2..05b898aa07 100644 --- a/book.toml +++ b/book.toml @@ -13,9 +13,11 @@ enable = true [output.html] git-repository-url = "https://github.com/rust-lang/rust-by-example" +hash-files = true additional-css = [ "theme/css/language-picker.css", ] +additional-js = ["theme/js/language-picker.js"] [rust] edition = "2021" diff --git a/theme/head.hbs b/theme/head.hbs new file mode 100644 index 0000000000..f9a6286907 --- /dev/null +++ b/theme/head.hbs @@ -0,0 +1,4 @@ + diff --git a/theme/index.hbs b/theme/index.hbs deleted file mode 100644 index 504b437742..0000000000 --- a/theme/index.hbs +++ /dev/null @@ -1,376 +0,0 @@ - - - - - - {{ title }} - {{#if is_print }} - - {{/if}} - {{#if base_url}} - - {{/if}} - - - - {{> head}} - - - - - - {{#if favicon_svg}} - - {{/if}} - {{#if favicon_png}} - - {{/if}} - - - - {{#if print_enable}} - - {{/if}} - - - - {{#if copy_fonts}} - - {{/if}} - - - - - - - - {{#each additional_css}} - - {{/each}} - - {{#if mathjax_support}} - - - {{/if}} - - - - - - - -
- - - - - - - - - - - - - -
- -
- {{> header}} - - - - {{#if search_enabled}} - - {{/if}} - - - - -
-
- {{{ content }}} -
- - -
-
- - - -
- - {{#if live_reload_endpoint}} - - - {{/if}} - - {{#if google_analytics}} - - - {{/if}} - - {{#if playground_line_numbers}} - - {{/if}} - - {{#if playground_copyable}} - - {{/if}} - - {{#if playground_js}} - - - - - - {{/if}} - - {{#if search_js}} - - - - {{/if}} - - - - - - - {{#each additional_js}} - - {{/each}} - - {{#if is_print}} - {{#if mathjax_support}} - - {{else}} - - {{/if}} - {{/if}} - -
- - diff --git a/theme/js/language-picker.js b/theme/js/language-picker.js new file mode 100644 index 0000000000..e8f34ed7d8 --- /dev/null +++ b/theme/js/language-picker.js @@ -0,0 +1,50 @@ +(function addThemePicker() { + const rightButtonsElement = document.querySelector('.right-buttons'); + rightButtonsElement.insertAdjacentHTML("afterbegin", ` + + + `); + + const language = document.documentElement.getAttribute("lang"); + let langToggle = document.getElementById("language-toggle"); + let langList = document.getElementById("language-list"); + langToggle.addEventListener("click", (event) => { + langList.style.display = + langList.style.display == "block" ? "none" : "block"; + }); + let selectedLang = document.getElementById(language); + if (selectedLang) { + selectedLang.parentNode.classList.add("theme-selected"); + } + + // The path to the root, taking the current language into account. + let full_path_to_root = + language == "en" ? `${mdbookPathToRoot}` : `${mdbookPathToRoot}../`; + // The page path (mdbook only gives us access to the path to the Markdown file). + let path = mdbookPath.replace(/\.md$/, ".html"); + for (let lang of langList.querySelectorAll("a")) { + if (lang.id == "en") { + lang.href = `${full_path_to_root}${path}`; + } else { + lang.href = `${full_path_to_root}${lang.id}/${path}`; + } + } +})();