Skip to content

Commit

Permalink
fix(404): 🐛 404.html cannot use predefined config params
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy-Liuxf committed Jun 5, 2024
1 parent 35aee97 commit fba747b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 53 deletions.
45 changes: 23 additions & 22 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@
<html lang="en-US">

<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{{ '/assets/css/style.css?v=' | append: site.github.build_revision | relative_url }}">
<script type="text/javascript"
src="{{ '/assets/js/prepare.js?v=' | append: site.github.build_revision | relative_url }}"></script>
<script>
if (lang_index !== -1) {
const lang = paths[lang_index];
if (lang === 'zh-CN') {
window.location.href = paths.slice(0, 4).join('/') + '/unavailable.html';
} else {
const new_paths = paths.slice(0, lang_index).concat(
lang === 'en-US' || lang === 'zh-TW' ? 'zh-CN' : 'en-US'
).concat(paths.slice(lang_index + 1));
window.location.href = new_paths.join('/').replace(/\.md$/, '.html');
}
} else {
window.location.href = paths.slice(0, 4).join('/') + '/unavailable.html';
}
</script>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
const current_url = window.location.origin + window.location.pathname;
const paths = current_url.split('/');
const pattern = /^(zh-CN|zh-TW|en-US|fr-FR)$/;
const lang_index = paths.findIndex(path => pattern.test(path));
if (lang_index !== -1) {
const lang = paths[lang_index];
if (lang === 'zh-CN') {
window.location.href = paths.slice(0, 4).join('/') + '/unavailable.html';
} else {
const new_paths = paths.slice(0, lang_index).concat(
lang === 'en-US' || lang === 'zh-TW' ? 'zh-CN' : 'en-US'
).concat(paths.slice(lang_index + 1));
window.location.href = new_paths.join('/').replace(/\.md$/, '.html');
}
} else {
window.location.href = paths.slice(0, 4).join('/') + '/unavailable.html';
}
</script>
</head>

<body>
<h2>404</h2>
<h2>404</h2>
</body>

</html>
31 changes: 0 additions & 31 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,6 @@
</script>
<script type="text/javascript"
src="{{ '/assets/js/prepare.js?v=' | append: site.github.build_revision | relative_url }}"></script>
<script type="text/javascript">
const viewOnGitHub = () => {
if (is_main_page) {
window.location.href = repo_url + '/';
} else {
let target = `${repo_url}/blob/${repo_branch}/${repo_path.replace(/\/$/, '')}`;
if (!target.endsWith('/')) {
target += '/';
}
target += current_url.slice(base_url.length + 1);
if (target.endsWith('/')) {
target += 'README.md';
} else if (target.endsWith('.html')) {
target = target.replace(/\.html$/, '.md');
}
window.location.href = target;
}
};

const returnToBackPage = () => {
if (lang_index !== -1) {
if (lang_index + 2 === paths.length) {
window.location.href = paths.slice(0, lang_index).join('/') + '/';
} else {
window.location.href = paths.slice(0, lang_index + 1).join('/') + '/';
}
} else {
window.location.href = paths.slice(0, 4).join('/') + '/'
}
};
</script>
{% include head-custom.html %}

{% seo %}
Expand Down
30 changes: 30 additions & 0 deletions assets/js/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,33 @@ const params = current_url.split('?')[1];
const hash = current_url.split('#')[1];

document.documentElement.lang = lang_index !== -1 ? paths[lang_index] : 'en-US';

const viewOnGitHub = () => {
if (is_main_page) {
window.location.href = repo_url + '/';
} else {
let target = `${repo_url}/blob/${repo_branch}/${repo_path.replace(/\/$/, '')}`;
if (!target.endsWith('/')) {
target += '/';
}
target += current_url.slice(base_url.length + 1);
if (target.endsWith('/')) {
target += 'README.md';
} else if (target.endsWith('.html')) {
target = target.replace(/\.html$/, '.md');
}
window.location.href = target;
}
};

const returnToBackPage = () => {
if (lang_index !== -1) {
if (lang_index + 2 === paths.length) {
window.location.href = paths.slice(0, lang_index).join('/') + '/';
} else {
window.location.href = paths.slice(0, lang_index + 1).join('/') + '/';
}
} else {
window.location.href = paths.slice(0, 4).join('/') + '/'
}
};

0 comments on commit fba747b

Please sign in to comment.