Skip to content

Commit 44d54cc

Browse files
Don't flash the 404 page when using it for redirects (#46)
1 parent 02e8f86 commit 44d54cc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/content/docs/404.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@ hero:
99

1010
import { latest_dir_name } from '../../../astro.config.mjs';
1111

12+
<style>{`.hero { display: none; }`}</style>
13+
1214
<script>{`
1315
window.onload = function () {
1416
const latest_dir_name = '${ latest_dir_name }';
1517
const path = window.location.pathname;
1618
// redirect /latest to the latest version
1719
if (path.startsWith('/latest')) {
1820
window.location.replace('/' + latest_dir_name + '/' + path.slice(path.length == 7 ? 7 : 8))
21+
return;
1922
}
2023
// redirect a semver (/2.0.1) to a directory name (/2_0)
2124
let parts = path.match(/^\\/(?<major>[0-9]+)\\.(?<minor>[0-9])+\\.[0-9]+(?<rest>\\/.*)?$/)?.groups;
2225
if (parts) {
23-
window.location.replace('/' + parts['major'] + '_' + parts['minor'] + (parts['rest'] || ''))
26+
window.location.replace('/' + parts['major'] + '_' + parts['minor'] + (parts['rest'] || ''));
27+
return;
2428
}
29+
document.getElementsByClassName('hero')[0].style = "display: inherit;";
2530
};
2631
`}</script>

0 commit comments

Comments
 (0)