1
1
---
2
2
import StarlightPage from ' @astrojs/starlight/components/StarlightPage.astro' ;
3
3
import { OLD_WIKI_URL , OLD_WIKI_REDIRECT } from ' @src/content.constants' ;
4
- const url = new URL (Astro .request .url );
5
- const pathname = url .pathname ;
6
- const redirectUrl = ` ${OLD_WIKI_URL }${pathname } ` ;
7
4
---
8
5
9
6
<StarlightPage frontmatter ={ {
@@ -14,28 +11,34 @@ const redirectUrl = `${OLD_WIKI_URL}${pathname}`;
14
11
tagline: Astro .locals .t (' 404.text' )
15
12
}
16
13
}} >
17
- <p >Sorry, the page <strong >{ pathname } </strong > could not be found.</p >
18
14
{ OLD_WIKI_REDIRECT && (
19
15
<p >This page doesn't exist here. You will be redirected to the old MTA Wiki in <strong ><span id = " countdown" >5</span > seconds...</p ></strong >
20
- <a href = { redirectUrl } target = " _blank" rel = " noopener noreferrer" >
16
+ <a href = " # " target = " _blank" rel = " noopener noreferrer" >
21
17
<p >Click here to view the page on the old MTA Wiki</p >
22
18
</a >
23
19
)}
24
20
</StarlightPage >
25
21
26
- <script is:inline define:vars ={ { OLD_WIKI_REDIRECT , redirectUrl }} >
22
+ <script is:inline define:vars ={ { OLD_WIKI_URL , OLD_WIKI_REDIRECT }} >
27
23
if (!OLD_WIKI_REDIRECT) {
28
24
return;
29
25
}
26
+ const gotoUrl = OLD_WIKI_URL + location.pathname;
30
27
let countdown = 5;
31
28
const el = document.getElementById('countdown');
29
+ const aEl = document.querySelector('a');
30
+ aEl.onclick = (e) => {
31
+ e.preventDefault();
32
+ clearInterval(interval);
33
+ window.location.href = gotoUrl;
34
+ };
32
35
33
36
const interval = setInterval(() => {
34
37
countdown -= 1;
35
38
if (el) el.textContent = countdown;
36
39
if (countdown <= 0) {
37
40
clearInterval(interval);
38
- window.location.href = redirectUrl ;
41
+ window.location.href = gotoUrl ;
39
42
}
40
43
}, 1000);
41
44
</script >
0 commit comments