Skip to content

Commit 326346c

Browse files
jdxclaude
andcommitted
docs: respect banner expires field
The banner.json endpoint now includes an optional ISO-8601 `expires` timestamp so announcements can auto-hide without a code change. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent b834ca7 commit 326346c

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

docs/.vitepress/theme/banner.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface BannerData {
66
message: string;
77
link?: string;
88
linkText?: string;
9+
expires?: string;
910
}
1011

1112
const ENDPOINT = "https://jdx.dev/banner.json";
@@ -17,12 +18,20 @@ export function initBanner(): void {
1718
.then((r) => (r.ok ? (r.json() as Promise<BannerData>) : null))
1819
.then((b) => {
1920
if (!b || !b.enabled) return;
21+
if (isExpired(b.expires)) return;
2022
if (localStorage.getItem(STORAGE_KEY) === b.id) return;
2123
render(b);
2224
})
2325
.catch(() => {});
2426
}
2527

28+
function isExpired(expires: string | undefined): boolean {
29+
if (!expires) return false;
30+
const t = Date.parse(expires);
31+
if (Number.isNaN(t)) return false;
32+
return Date.now() >= t;
33+
}
34+
2635
function isHttpUrl(value: string): boolean {
2736
try {
2837
const u = new URL(value, window.location.href);

0 commit comments

Comments
 (0)