File tree Expand file tree Collapse file tree 2 files changed +23
-7
lines changed Expand file tree Collapse file tree 2 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 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
88A ` Path ` can be created from an ` OsStr ` , and provides several methods to get
99information 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
Original file line number Diff line number Diff line change 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 ( / \. m d $ / , ".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} ) ( ) ;
You can’t perform that action at this time.
0 commit comments