File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ additional-css = [
7272site-url = " /comprehensive-rust/"
7373git-repository-url = " https://github.com/google/comprehensive-rust"
7474edit-url-template = " https://github.com/google/comprehensive-rust/edit/main/{path}"
75+ input-404 = " 404.md"
7576
7677[output .html .fold ]
7778enable = true
Original file line number Diff line number Diff line change 1+ # Document not found (404)
2+
3+ This URL is invalid, sorry. Please use the navigation bar or search to continue.
4+
5+ <script >
6+ (function () {
7+ const baseEl = document .querySelector (" base" );
8+ const baseHref = baseEl ? baseEl .getAttribute (" href" ) || " /" : " /" ;
9+ const knownLangs = new Set (
10+ Array .from (document .querySelectorAll (" #language-list a[id]" ), (link ) => link .id ),
11+ );
12+
13+ const basePath = new URL (baseHref, window .location .origin ).pathname ;
14+
15+ const fullPath = window .location .pathname ;
16+
17+ let relPath = fullPath .startsWith (basePath)
18+ ? fullPath .slice (basePath .length )
19+ : fullPath .replace (/ ^ \/ + / , " " );
20+
21+ if (! relPath) {
22+ return ;
23+ }
24+
25+ const segments = relPath .split (" /" );
26+ const maybeLang = segments[0 ];
27+
28+ if (! knownLangs .has (maybeLang) || maybeLang === " en" ) {
29+ return ;
30+ }
31+
32+ if (relPath === maybeLang + " /404.html" || relPath === " 404.html" ) {
33+ return ;
34+ }
35+
36+ const targetUrl = new URL (maybeLang + " /404.html" , baseHref).toString ();
37+ window .location .replace (targetUrl);
38+ })();
39+ </script >
You can’t perform that action at this time.
0 commit comments