From 2c6f3cc4fd65a0e178d75cb76c656f6e9e2ad951 Mon Sep 17 00:00:00 2001 From: scottmakestech <83726258+scottmakestech@users.noreply.github.com> Date: Thu, 12 Nov 2026 22:04:07 -0600 Subject: [PATCH] December 2026 donate banners --- README.md | 15 ++++++ hugo.toml | 25 +++++++++ layouts/_default/baseof.html | 7 --- layouts/blog/baseof.html | 7 --- layouts/index.html | 8 --- layouts/initiative/baseof.html | 7 --- layouts/partials/header.html | 1 + layouts/partials/site-banner.html | 21 ++++++++ static/site-banner/site-banner.css | 85 ++++++++++++++++++++++++++++++ static/site-banner/site-banner.js | 85 ++++++++++++++++++++++++++++++ static/site-banner/theme.css | 7 +++ 11 files changed, 239 insertions(+), 29 deletions(-) create mode 100644 layouts/partials/site-banner.html create mode 100644 static/site-banner/site-banner.css create mode 100644 static/site-banner/site-banner.js create mode 100644 static/site-banner/theme.css diff --git a/README.md b/README.md index 465f8882..631e9c52 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,18 @@ browser. Note that the -F flag will show items to be published in the future (like blog posts with dates in the future). To view the 404 page when running locally, use /404.html. + +## Site banner + +`layouts/partials/site-banner.html` shows a dismissible banner below the navigation on English pages. All of its settings go in the site config under `[params]`: + +```toml +site_banner_enabled = true +site_banner_text = "Message" +site_banner_href = "https://example.org/" # optional link +site_banner_label = "Button text" # optional; without it the message is the link +``` + +For messages with dates, add `[[params.site_banner_schedule]]` entries with `start`, `end` and `text`, plus optional `href`, `label` and `id`. Times are ISO 8601 with an offset; an entry without `href` or `label` uses the ones above. While a scheduled message is active, it replaces the simple banner. Colors are in `static/site-banner/theme.css`. Closing the banner is remembered in the browser's `localStorage` (no cookies). + +On Netlify previews and local builds, `?banner-time=` (for example `?banner-time=2026-12-01T18:00:00Z`) or `?banner=` previews the schedule. The live site ignores both. diff --git a/hugo.toml b/hugo.toml index 4cfc68cb..119537ea 100644 --- a/hugo.toml +++ b/hugo.toml @@ -54,3 +54,28 @@ description = "ISRG's Prossimo is moving critical software to memory safe code." # Hugo 0.162+ refuses HTML content files by default. Several pages on this site # (about, contact, sponsor, and the initiative pages) are hand-written HTML. allowContent = ['^text/markdown$', '^text/html$'] + +# Site banner messages with dates; see "Site banner" in README.md. +[[params.site_banner_schedule]] +id = "giving-tuesday" +start = "2026-12-01T00:00:00-06:00" +end = "2026-12-02T00:00:00-06:00" +text = "It’s Giving Tuesday! As a nonprofit, we rely on our generous community of donors." +label = "Donate Today" +href = "https://www.abetterinternet.org/donate/" + +[[params.site_banner_schedule]] +id = "monthly" +start = "2026-12-02T00:00:00-06:00" +end = "2026-12-26T00:00:00-06:00" +text = "As we look toward 2027, consider a gift that keeps on giving. Internet security!" +label = "Donate monthly" +href = "https://www.abetterinternet.org/donate/" + +[[params.site_banner_schedule]] +id = "year-end" +start = "2026-12-26T00:00:00-06:00" +end = "2027-01-01T00:00:00-06:00" +text = "ISRG protects billions of people online, every day. Join us by making a donation before December 31 to finish the year strong." +label = "Donate Today" +href = "https://www.abetterinternet.org/donate/" diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index a84305e5..b7d64108 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,13 +1,6 @@ {{ partial "head.html" . }} {{ partial "header.html" . }} - {{ if .Site.Params.site_banner_enabled }} - {{ if .Site.Params.site_banner_text }} - - {{ end }} -{{ end }}
diff --git a/layouts/blog/baseof.html b/layouts/blog/baseof.html index c02c7545..d7470a1e 100644 --- a/layouts/blog/baseof.html +++ b/layouts/blog/baseof.html @@ -1,13 +1,6 @@ {{ partial "head.html" . }} {{ partial "header.html" . }} - {{ if .Site.Params.site_banner_enabled }} - {{ if .Site.Params.site_banner_text }} - - {{ end }} - {{ end }}
diff --git a/layouts/index.html b/layouts/index.html index c3c15d36..b54a7e24 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -32,14 +32,6 @@

for the Internet's most critical infrastructure

- {{ if .Site.Params.site_banner_enabled }} - {{ if .Site.Params.site_banner_text }} - - {{ end }} - {{ end }} -
diff --git a/layouts/initiative/baseof.html b/layouts/initiative/baseof.html index 62bfa5ce..350166d5 100644 --- a/layouts/initiative/baseof.html +++ b/layouts/initiative/baseof.html @@ -3,13 +3,6 @@ {{ partial "head.html" . }} {{ partial "header.html" . }} {{ partial "initiative/initiative_hero.html" .}} - {{ if .Site.Params.site_banner_enabled }} - {{ if .Site.Params.site_banner_text }} - - {{ end }} - {{ end }}
diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 06b9b1b2..a1786255 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -122,3 +122,4 @@
+ {{ partial "site-banner.html" (dict "page" . "container" "container px-0 px-xl-3") }} diff --git a/layouts/partials/site-banner.html b/layouts/partials/site-banner.html new file mode 100644 index 00000000..5ce31720 --- /dev/null +++ b/layouts/partials/site-banner.html @@ -0,0 +1,21 @@ +{{/* Site banner. Settings: site_banner_* params in the site config. Styles: static/site-banner/. See "Site banner" in README.md. + Include with the header's container classes so the banner lines up with the navigation: + {{ partial "site-banner.html" (dict "page" . "container" "container") }} */}} +{{ $page := .page }} +{{ $p := site.Params }} +{{ $schedule := $p.site_banner_schedule | default slice }} +{{ if and (eq $page.Language.Lang "en") (or $p.site_banner_enabled $schedule) }} + {{ $config := dict "enabled" ($p.site_banner_enabled | default false) "text" ($p.site_banner_text | default "") "href" ($p.site_banner_href | default "") "label" ($p.site_banner_label | default "") "schedule" $schedule }} + + + + +{{ end }} diff --git a/static/site-banner/site-banner.css b/static/site-banner/site-banner.css new file mode 100644 index 00000000..b3f7067c --- /dev/null +++ b/static/site-banner/site-banner.css @@ -0,0 +1,85 @@ +.site-banner[hidden] { display: none !important; } +.site-banner { + background: var(--site-banner-bg, #12365a); + color: var(--site-banner-text, #fff); + font-family: inherit; + position: relative; + z-index: 2; + /* Match the navbar's side padding; set per site in theme.css. */ + padding-inline: var(--site-banner-gutter, 0px); +} +.site-banner, .site-banner * { box-sizing: border-box; } +.site-banner__inner { + padding-block: 20px; + display: grid; + grid-template-columns: minmax(0, 1fr) auto 44px; + align-items: center; + gap: 20px; +} +.site-banner .site-banner__message { + margin: 0; + color: inherit; + font: inherit; + font-size: 17px; + line-height: 1.5; + font-weight: 600; +} +.site-banner .site-banner__cta { + display: inline-flex; + align-items: center; + justify-content: center; + min-height: 44px; + padding: 8px 20px; + border: 2px solid transparent; + border-radius: 6px; + background: var(--site-banner-button, #fff); + color: var(--site-banner-button-text, #12365a) !important; + font: inherit; + font-size: 16px; + font-weight: 700; + line-height: 1.4; + text-decoration: none; + white-space: nowrap; +} +.site-banner .site-banner__cta:hover { text-decoration: underline; } +.site-banner .site-banner__cta[hidden] { display: none; } +.site-banner .site-banner__message a { color: inherit; text-decoration: underline; } +.site-banner .site-banner__close { + display: flex; + justify-content: center; + align-items: center; + width: 44px; + height: 44px; + padding: 0; + border: 0; + border-radius: 50%; + background: transparent; + box-shadow: none; + color: inherit; + font: inherit; + line-height: 1; + cursor: pointer; + /* The X is drawn 14px inside the button; shift it so the X meets the container edge. */ + margin-right: -14px; + justify-self: end; +} +.site-banner .site-banner__close:hover { background: color-mix(in srgb, currentColor 14%, transparent); } +.site-banner .site-banner__close:active { background: color-mix(in srgb, currentColor 24%, transparent); } +.site-banner .site-banner__close svg { + display: block; + width: 24px; + height: 24px; + flex: none; +} +.site-banner .site-banner__cta:focus-visible, +.site-banner .site-banner__close:focus-visible { + outline: 3px solid var(--site-banner-text, #fff); + outline-offset: 4px; +} +.site-banner__close { grid-column: 3; } +@media (max-width: 640px) { + .site-banner__inner { grid-template-columns: minmax(0, 1fr) 44px; gap: 12px 16px; padding-block: 16px; } + .site-banner__message { grid-column: 1; grid-row: 1; } + .site-banner__cta { grid-column: 1; grid-row: 2; justify-self: start; } + .site-banner__close { grid-column: 2; grid-row: 1; align-self: start; } +} diff --git a/static/site-banner/site-banner.js b/static/site-banner/site-banner.js new file mode 100644 index 00000000..c382df1c --- /dev/null +++ b/static/site-banner/site-banner.js @@ -0,0 +1,85 @@ +/* Site banner. Settings: site_banner_* params in the site config; see "Site banner" in README.md. + * A scheduled message replaces the simple banner while it is active. + * On Netlify previews and local builds, ?banner-time= or ?banner= previews the schedule. + */ +(() => { + "use strict"; + const root = document.querySelector("[data-site-banner]"); + if (!root) return; + const config = JSON.parse(root.dataset.siteBanner); + const message = root.querySelector(".site-banner__message"); + const button = root.querySelector(".site-banner__cta"); + const close = root.querySelector(".site-banner__close"); + const schedule = config.schedule || []; + const simple = config.enabled && config.text ? config : null; + const host = window.location.hostname; + const previewHost = /--.+\.netlify\.app$/.test(host) || host === "localhost" || host === "127.0.0.1"; + const query = new URLSearchParams(previewHost ? window.location.search : ""); + const pinned = schedule.find(entry => entry.id && entry.id === query.get("banner")); + const previewTime = Date.parse(query.get("banner-time") || ""); + const previewing = Boolean(pinned) || !Number.isNaN(previewTime); + const key = banner => "site-banner:" + (banner.start || "") + ":" + banner.text; + const dismissed = new Set(); + let active; + let timer; + const isDismissed = banner => { + if (dismissed.has(key(banner))) return true; + if (previewing) return false; + try { return localStorage.getItem(key(banner)) === "1"; } catch { return false; } + }; + const show = banner => { + const href = banner.href || config.href; + const label = banner.label || config.label; + if (href && !label) { + const link = document.createElement("a"); + link.href = href; + link.textContent = banner.text; + message.replaceChildren(link); + } else { + message.replaceChildren(banner.text); + } + button.hidden = !(href && label); + if (href && label) { + button.href = href; + button.textContent = label; + } + }; + // Some themes float the header over the page; reserve its height without changing its behavior. + const header = document.querySelector("header"); + const position = () => { + root.style.marginBlockStart = ""; + if (root.hidden || !header) return; + const mode = getComputedStyle(header).position; + if (mode !== "absolute" && mode !== "fixed") return; + const bottom = header.getBoundingClientRect().bottom + (mode === "fixed" ? 0 : window.scrollY); + const top = root.getBoundingClientRect().top + window.scrollY; + root.style.marginBlockStart = Math.max(0, bottom - top) + "px"; + }; + const render = () => { + clearTimeout(timer); + const now = Number.isNaN(previewTime) ? Date.now() : previewTime; + active = pinned || schedule.find(entry => now >= Date.parse(entry.start) && now < Date.parse(entry.end)) || simple; + root.hidden = !active || isDismissed(active); + if (!root.hidden) show(active); + position(); + if (previewing) return; + // Recheck at the next start or end, and at least once a minute for clock changes and throttled tabs. + const next = schedule.flatMap(entry => [Date.parse(entry.start), Date.parse(entry.end)]).filter(time => time > now); + if (next.length) timer = setTimeout(render, Math.min(60000, Math.min(...next) - now)); + }; + close.addEventListener("click", () => { + if (!active) return; + dismissed.add(key(active)); + if (!previewing) { + try { localStorage.setItem(key(active), "1"); } catch { /* Kept for this page view only. */ } + } + render(); + }); + document.addEventListener("visibilitychange", render); + window.addEventListener("pageshow", render); + window.addEventListener("focus", render); + window.addEventListener("storage", render); + window.addEventListener("resize", position); + if (header && window.ResizeObserver) new ResizeObserver(position).observe(header); + render(); +})(); diff --git a/static/site-banner/theme.css b/static/site-banner/theme.css new file mode 100644 index 00000000..87805f2b --- /dev/null +++ b/static/site-banner/theme.css @@ -0,0 +1,7 @@ +.site-banner { + --site-banner-bg: #082659; + --site-banner-text: #ffffff; + --site-banner-button: #14dfb4; + --site-banner-button-text: #082659; + --site-banner-gutter: 16px; +}