mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-25 16:54:32 +02:00
Add language picker menu (#411)
The picker is a drop-down menu using the same design as the theme picker in the top-left. There doesn’t seem to be an easy way to pass in a list of languages and descriptions, so for now we’ll have to expand the menu by hand as we add new languages. A comment has been added to `publish.yml` to remind us of this.
This commit is contained in:
parent
8e4bf245d3
commit
3b7123d21a
1
.github/workflows/publish.yml
vendored
1
.github/workflows/publish.yml
vendored
@ -18,6 +18,7 @@ concurrency:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
# Update the language picker in index.hbs to link new languages.
|
||||||
LANGUAGES: da pt-BR
|
LANGUAGES: da pt-BR
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
@ -31,7 +31,7 @@ class = "bob"
|
|||||||
[output.html]
|
[output.html]
|
||||||
curly-quotes = true
|
curly-quotes = true
|
||||||
additional-js = ["ga4.js", "speaker-notes.js"]
|
additional-js = ["ga4.js", "speaker-notes.js"]
|
||||||
additional-css = ["svgbob.css", "speaker-notes.css"]
|
additional-css = ["svgbob.css", "speaker-notes.css", "language-picker.css"]
|
||||||
site-url = "/comprehensive-rust/"
|
site-url = "/comprehensive-rust/"
|
||||||
git-repository-url = "https://github.com/google/comprehensive-rust"
|
git-repository-url = "https://github.com/google/comprehensive-rust"
|
||||||
edit-url-template = "https://github.com/google/comprehensive-rust/edit/main/{path}"
|
edit-url-template = "https://github.com/google/comprehensive-rust/edit/main/{path}"
|
||||||
|
8
language-picker.css
Normal file
8
language-picker.css
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#language-list {
|
||||||
|
left: auto;
|
||||||
|
right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#language-list a {
|
||||||
|
color: inherit;
|
||||||
|
}
|
@ -147,6 +147,40 @@
|
|||||||
<h1 class="menu-title">{{ book_title }}</h1>
|
<h1 class="menu-title">{{ book_title }}</h1>
|
||||||
|
|
||||||
<div class="right-buttons">
|
<div class="right-buttons">
|
||||||
|
<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="pt-BR">Brazilian Portuguese</a>
|
||||||
|
</button></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
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 }}");
|
||||||
|
selectedLang.parentNode.classList.add("theme-selected");
|
||||||
|
for (let lang of langList.querySelectorAll("a")) {
|
||||||
|
if (lang.id == "en") {
|
||||||
|
lang.href = "{{ path_to_root }}{{ path }}";
|
||||||
|
} else {
|
||||||
|
lang.href = `{{ path_to_root }}${lang.id}/{{ path }}`;
|
||||||
|
}
|
||||||
|
lang.href = lang.href.replace(/\.md$/, ".html");
|
||||||
|
console.log(lang);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
{{#if print_enable}}
|
{{#if print_enable}}
|
||||||
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book">
|
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book">
|
||||||
<i id="print-button" class="fa fa-print"></i>
|
<i id="print-button" class="fa fa-print"></i>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user