Skip to content

Update mdbook to 0.4.46 #1914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rbe.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions theme/head.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script>
const mdbookPath = "{{ path }}";
const mdbookPathToRoot = "{{ path_to_root }}";
</script>
376 changes: 0 additions & 376 deletions theme/index.hbs

This file was deleted.

50 changes: 50 additions & 0 deletions theme/js/language-picker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
(function addThemePicker() {
const rightButtonsElement = document.querySelector('.right-buttons');
rightButtonsElement.insertAdjacentHTML("afterbegin", `
<button id="language-toggle" class="icon-button" type="button"
title="Change language" aria-label="Change language"
aria-haspopup="true" aria-expanded="false"
aria-controls="language-list">
<i class="fa fa-globe"></i>
</button>
<ul id="language-list" class="theme-popup" aria-label="Languages" role="menu">
<li role="none"><button role="menuitem" class="theme">
<a id="en">English</a>
</button></li>
<li role="none"><button role="menuitem" class="theme">
<a id="ja">日本語</a>
</button></li>
<li role="none"><button role="menuitem" class="theme">
<a id="zh">中文</a>
</button></li>
<li role="none"><button role="menuitem" class="theme">
<a id="es">Español</a>
</button></li>
</ul>
`);

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}`;
}
}
})();