From bf579fdb9f606aeda1a4a86e3b7187b2e80418df Mon Sep 17 00:00:00 2001 From: alex-mills Date: Fri, 4 Sep 2026 14:02:28 -0500 Subject: [PATCH] feat(site): add dismissible announcement bar --- public/announcement-bar.js | 33 +++++ src/components/AnnouncementBar.astro | 205 +++++++++++++++++++++++++++ src/layouts/Layout.astro | 9 ++ 3 files changed, 247 insertions(+) create mode 100644 public/announcement-bar.js create mode 100644 src/components/AnnouncementBar.astro diff --git a/public/announcement-bar.js b/public/announcement-bar.js new file mode 100644 index 0000000..25a17ad --- /dev/null +++ b/public/announcement-bar.js @@ -0,0 +1,33 @@ +const bars = document.querySelectorAll("[data-announcement-bar]"); + +for (const bar of bars) { + const storageKey = bar.dataset.storageKey; + let dismissed = false; + + if (storageKey) { + try { + dismissed = localStorage.getItem(storageKey) === "dismissed"; + } catch { + // Storage can be unavailable; dismissal still works for this page view. + } + } + + if (dismissed) continue; + + bar.hidden = false; + const dismissButton = bar.querySelector("[data-announcement-dismiss]"); + dismissButton?.addEventListener( + "click", + () => { + bar.hidden = true; + if (!storageKey) return; + + try { + localStorage.setItem(storageKey, "dismissed"); + } catch { + // The bar remains dismissed for this page view when storage is blocked. + } + }, + { once: true }, + ); +} diff --git a/src/components/AnnouncementBar.astro b/src/components/AnnouncementBar.astro new file mode 100644 index 0000000..2f51832 --- /dev/null +++ b/src/components/AnnouncementBar.astro @@ -0,0 +1,205 @@ +--- +interface Props { + storageKey: string; + message: string; + href: string; + linkLabel: string; + tone?: "ember" | "rust" | "mint" | "copper" | "electric" | "gold" | "cyan" | "amber" | "lime"; +} + +const { + storageKey, + message, + href, + linkLabel, + tone = "ember", +} = Astro.props; +const external = /^https?:\/\//.test(href); +--- + + + + + + diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 7466c15..a340202 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -1,4 +1,6 @@ --- +import AnnouncementBar from '../components/AnnouncementBar.astro'; + interface Props { title: string; description: string; @@ -47,6 +49,13 @@ const csp = [ +