diff --git a/src/std_misc/path.md b/src/std_misc/path.md index 7fd931fcaf..b547e83c0c 100644 --- a/src/std_misc/path.md +++ b/src/std_misc/path.md @@ -1,9 +1,9 @@ # Path -The `Path` struct represents file paths in the underlying filesystem. There are -two flavors of `Path`: `posix::Path`, for UNIX-like systems, and -`windows::Path`, for Windows. The prelude exports the appropriate -platform-specific `Path` variant. +The `Path` type represents file paths in the underlying filesystem. Across all +platforms there is a single `std::path::Path` that abstracts over +platform-specific path semantics and separators. Bring it into scope with +`use std::path::Path;` when needed. A `Path` can be created from an `OsStr`, and provides several methods to get information from the file/directory the path points to. @@ -47,8 +47,7 @@ fn main() { } ``` -Be sure to check at other `Path` methods (`posix::Path` or `windows::Path`) and -the `Metadata` struct. +Be sure to check other `Path` methods and the `Metadata` struct. ### See also: diff --git a/theme/js/language-picker.js b/theme/js/language-picker.js index e8f34ed7d8..02d8d18d9e 100644 --- a/theme/js/language-picker.js +++ b/theme/js/language-picker.js @@ -40,11 +40,28 @@ 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")) { + const langAnchors = Array.from(langList.querySelectorAll("a")); + for (let lang of langAnchors) { if (lang.id == "en") { lang.href = `${full_path_to_root}${path}`; } else { lang.href = `${full_path_to_root}${lang.id}/${path}`; } } + + // Hide languages whose target page is not available (e.g., not deployed). + // This prevents users from hitting 404s on sites that only ship some locales. + for (let lang of langAnchors) { + const url = lang.href; + // Attempt a lightweight HEAD request; fall back to hiding on failure. + fetch(url, { method: "HEAD" }).then((resp) => { + if (!resp.ok) { + const li = lang.parentNode && lang.parentNode.parentNode; + if (li) li.style.display = "none"; + } + }).catch(() => { + const li = lang.parentNode && lang.parentNode.parentNode; + if (li) li.style.display = "none"; + }); + } })();