1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-31 01:38:16 +02:00

Fix links in language picker (#417)

When the current page is not `en`, we need to add an additional `../`
to the path to reach the top of the site.
This commit is contained in:
Martin Geisler 2023-02-15 18:59:58 +01:00 committed by GitHub
parent 747589ae8c
commit 14b5e86579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -170,14 +170,23 @@
});
let selectedLang = document.getElementById("{{ language }}");
selectedLang.parentNode.classList.add("theme-selected");
// The path to the root, taking the current
// language into account.
{{#if (eq language "en")}}
let full_path_to_root = "{{ path_to_root }}";
{{else}}
let full_path_to_root = "{{ path_to_root }}../";
{{/if}}
// The page path (mdbook only gives us
// access to the path to the Markdown file).
let path = "{{ path }}".replace(/\.md$/, ".html");
for (let lang of langList.querySelectorAll("a")) {
if (lang.id == "en") {
lang.href = "{{ path_to_root }}{{ path }}";
lang.href = `${full_path_to_root}${path}`;
} else {
lang.href = `{{ path_to_root }}${lang.id}/{{ path }}`;
lang.href = `${full_path_to_root}${lang.id}/${path}`;
}
lang.href = lang.href.replace(/\.md$/, ".html");
console.log(lang);
}
</script>