Skip to content

Commit f944161

Browse files
authored
Merge pull request #1972 from marktech0813/master
Revise `Path` type documentation for clarity
2 parents 160e6bb + 9ff7027 commit f944161

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/std_misc/path.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Path
22

3-
The `Path` struct represents file paths in the underlying filesystem. There are
4-
two flavors of `Path`: `posix::Path`, for UNIX-like systems, and
5-
`windows::Path`, for Windows. The prelude exports the appropriate
6-
platform-specific `Path` variant.
3+
The `Path` type represents file paths in the underlying filesystem. Across all
4+
platforms there is a single `std::path::Path` that abstracts over
5+
platform-specific path semantics and separators. Bring it into scope with
6+
`use std::path::Path;` when needed.
77

88
A `Path` can be created from an `OsStr`, and provides several methods to get
99
information from the file/directory the path points to.
@@ -47,8 +47,7 @@ fn main() {
4747
}
4848
```
4949

50-
Be sure to check at other `Path` methods (`posix::Path` or `windows::Path`) and
51-
the `Metadata` struct.
50+
Be sure to check other `Path` methods and the `Metadata` struct.
5251

5352
### See also:
5453

theme/js/language-picker.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,28 @@
4040
language == "en" ? `${mdbookPathToRoot}` : `${mdbookPathToRoot}../`;
4141
// The page path (mdbook only gives us access to the path to the Markdown file).
4242
let path = mdbookPath.replace(/\.md$/, ".html");
43-
for (let lang of langList.querySelectorAll("a")) {
43+
const langAnchors = Array.from(langList.querySelectorAll("a"));
44+
for (let lang of langAnchors) {
4445
if (lang.id == "en") {
4546
lang.href = `${full_path_to_root}${path}`;
4647
} else {
4748
lang.href = `${full_path_to_root}${lang.id}/${path}`;
4849
}
4950
}
51+
52+
// Hide languages whose target page is not available (e.g., not deployed).
53+
// This prevents users from hitting 404s on sites that only ship some locales.
54+
for (let lang of langAnchors) {
55+
const url = lang.href;
56+
// Attempt a lightweight HEAD request; fall back to hiding on failure.
57+
fetch(url, { method: "HEAD" }).then((resp) => {
58+
if (!resp.ok) {
59+
const li = lang.parentNode && lang.parentNode.parentNode;
60+
if (li) li.style.display = "none";
61+
}
62+
}).catch(() => {
63+
const li = lang.parentNode && lang.parentNode.parentNode;
64+
if (li) li.style.display = "none";
65+
});
66+
}
5067
})();

0 commit comments

Comments
 (0)