Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions 404.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ sitemap: false

<script>
(function() {
// Detect language from URL path
var path = window.location.pathname;
var match = path.match(/^\/(bg|de|en|es|fr|id|it|ja|ko|pl|pt|ru|tr|ua|vi|zh_cn|zh_tw)\//);

if (match && match[1] !== 'en') {
var lang = match[1];
// Redirect to language-specific 404 page
window.location.href = '/' + lang + '/404.html';
}
const languages = {{ site.data.languages | map: "code" | jsonify }};
const path = window.location.pathname;
const match = path.match(/^\/([^\/]+)(\/.*)$/);
if (!match || match[1] === 'en' || !languages.includes(match[1])) return;
const notFound = '/' + match[1] + '/404.html';
// A language without its own 404 page is served this page again there
if (path === notFound) return;
// Fall back to the English page when a translation does not exist
const english = '/en' + match[2];
fetch(english, { method: 'HEAD' })
.then(function(res) { return res.ok; }, function() { return false; })
.then(function(found) {
window.location.replace(found ? english + window.location.search + window.location.hash : notFound);
});
})();
</script>

Expand Down