11---
22import HitsInfo from " @components/react/HitsInfo" ;
3- import { Aside } from " @astrojs/starlight/components " ;
3+ import AutoRedirect from " @components/react/AutoRedirect " ;
44import DefaultPageTitle from " @astrojs/starlight/components/PageTitle.astro" ;
55
66let tag = Astro .url .href ;
@@ -10,25 +10,16 @@ if (!tag.endsWith("/") && !tag.endsWith(".html")) {
1010
1111const { autoRedirect, contributors } = Astro .locals .starlightRoute .entry .data ;
1212const showContributors = Array .isArray (contributors ) && contributors .length > 0 ;
13-
14- const clientVars = autoRedirect ?? { delay: 0 , href: " " };
1513---
1614
1715{
1816 autoRedirect && (
19- <div id = " auto-redirect" >
20- <Aside type = " tip" >
21- { " 页面将在 " }
22- <span id = " auto-redirect-countdown" >{ autoRedirect .delay } </span >
23- { " 秒后自动跳转到" }
24- <a href = { autoRedirect .href } >{ autoRedirect .text } </a >
25- { " ,您也可以手动" }
26- <a href = " javascript:;" id = " auto-redirect-cancel" >
27- { " 取消跳转" }
28- </a >
29- 。
30- </Aside >
31- </div >
17+ <AutoRedirect
18+ client :only = " react"
19+ delay = { autoRedirect .delay }
20+ text = { autoRedirect .text }
21+ href = { autoRedirect .href }
22+ />
3223 )
3324}
3425
@@ -55,25 +46,3 @@ const clientVars = autoRedirect ?? { delay: 0, href: "" };
5546 )
5647 }
5748</div >
58-
59- <script is:inline define:vars ={ clientVars } >
60- const autoRedirect = document.getElementById("auto-redirect");
61- if (!autoRedirect) return;
62- const autoRedirectCountdown = document.getElementById("auto-redirect-countdown");
63- if (autoRedirectCountdown && delay > 0) {
64- let countdown = delay;
65- const autoRedirectCancel = document.getElementById("auto-redirect-cancel");
66- const interval = setInterval(() => {
67- if (countdown > 0) {
68- autoRedirectCountdown.textContent = String(--countdown);
69- } else {
70- clearInterval(interval);
71- location.href = href;
72- }
73- }, 1000);
74- autoRedirectCancel.addEventListener("click", () => {
75- clearInterval(interval);
76- autoRedirect.style.display = "none";
77- });
78- }
79- </script >
0 commit comments