Skip to content

Commit db180fa

Browse files
committed
支持页面定时跳转
1 parent 67173d6 commit db180fa

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

src/components/starlight/PageTitle.astro

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
---
2-
import DefaultPageTitle from "@astrojs/starlight/components/PageTitle.astro";
32
import HitsInfo from "@components/react/HitsInfo";
3+
import { Aside } from "@astrojs/starlight/components";
4+
import DefaultPageTitle from "@astrojs/starlight/components/PageTitle.astro";
45
56
let tag = Astro.url.href;
67
if (!tag.endsWith("/") && !tag.endsWith(".html")) {
78
tag += ".html";
89
}
910
10-
const { contributors } = Astro.locals.starlightRoute.entry.data;
11+
const { autoRedirect, contributors } = Astro.locals.starlightRoute.entry.data;
1112
const showContributors = Array.isArray(contributors) && contributors.length > 0;
13+
14+
const clientVars = autoRedirect ?? { delay: 0, href: "" };
1215
---
1316

17+
{
18+
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>
32+
)
33+
}
34+
1435
<DefaultPageTitle />
1536

1637
<div class="info">
@@ -29,3 +50,25 @@ const showContributors = Array.isArray(contributors) && contributors.length > 0;
2950
client:only="react"
3051
/>
3152
</div>
53+
54+
<script is:inline define:vars={clientVars}>
55+
const autoRedirect = document.getElementById("auto-redirect");
56+
if (!autoRedirect) return;
57+
const autoRedirectCountdown = document.getElementById("auto-redirect-countdown");
58+
if (autoRedirectCountdown && delay > 0) {
59+
let countdown = delay;
60+
const autoRedirectCancel = document.getElementById("auto-redirect-cancel");
61+
const interval = setInterval(() => {
62+
if (countdown > 0) {
63+
autoRedirectCountdown.textContent = String(--countdown);
64+
} else {
65+
clearInterval(interval);
66+
location.href = href;
67+
}
68+
}, 1000);
69+
autoRedirectCancel.addEventListener("click", () => {
70+
clearInterval(interval);
71+
autoRedirect.style.display = "none";
72+
});
73+
}
74+
</script>

src/content.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ export const collections = {
1919
})
2020
)
2121
.optional(),
22+
autoRedirect: z
23+
.object({
24+
delay: z.number(),
25+
text: z.string(),
26+
href: z.string(),
27+
})
28+
.optional(),
2229
}),
2330
}),
2431
}),
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ title: 反馈
33
contributors:
44
- Burning_TNT
55
- TyMxy
6+
autoRedirect:
7+
delay: 10
8+
text: 反馈表单
9+
href: https://f.kdocs.cn/ksform/w/write/njMwdtgD?channel=mdlsjp
610
tableOfContents: false
711
lastUpdated: 2025-12-03T16:39:00+08:00
812
---
913

10-
import { Aside } from "@astrojs/starlight/components";
11-
12-
<Aside type="tip">
13-
欢迎您填写[反馈表单](https://f.kdocs.cn/ksform/w/write/njMwdtgD?channel=mdlsjp)
14-
</Aside>
14+
:::tip
15+
欢迎您填写[反馈表单](https://f.kdocs.cn/ksform/w/write/njMwdtgD?channel=mdlsjp)
16+
:::
1517

1618
我们注意到了 EasyTier 项目。它提供了一种简单、安全、去中心化的异地组网方案,足以承载 Minecraft 的联机需求。
1719
在 EasyTier 开发团队的帮助下,我们决定重新在启动器内提供联机服务。

0 commit comments

Comments
 (0)