From 05a91d4d65913ccaa855dc8d20a947ff5b6bba4c 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 ++++++ config.toml | 32 +++++++++-- layouts/partials/header.html | 6 +-- 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 +++ 7 files changed, 242 insertions(+), 9 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 12a60e2..a4b48fd 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/config.toml b/config.toml index 07a273b..f9ae518 100644 --- a/config.toml +++ b/config.toml @@ -12,10 +12,10 @@ address_line_2 = "San Francisco, California 94104-5401" images = ["images/DivviUpSocialShare.png"] meta_description = "Divvi Up is a privacy-respecting telemetry service for web, mobile, and machine learning applications, brought to you by the Internet Security Research Group." social_share_twitter_square = "/images/DivviUpSocialShare-Twitter.png" -promoAnnouncementEnabled = false -# Previous usage of promoAnnouncementLink and promoAnnouncementText -promoAnnouncementLink = "https://abetterinternet.org/tenth-anniversary" -promoAnnouncementText = "ISRG celebrates 10 years of helping build a brighter Internet" +site_banner_enabled = false +# Previous usage of site_banner_href and site_banner_text +site_banner_href = "https://abetterinternet.org/tenth-anniversary" +site_banner_text = "ISRG celebrates 10 years of helping build a brighter Internet" # Date and time formatting, see https://gohugo.io/functions/format/ @@ -44,3 +44,27 @@ weight = 1 [languages.en.params] description = "Divvi Up is a privacy-respecting telemetry service for web, mobile, and machine learning applications, brought to you by the Internet Security Research Group." +# 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/partials/header.html b/layouts/partials/header.html index 64e9991..6262dc2 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -103,8 +103,4 @@ - {{ if .Site.Params.promoAnnouncementEnabled }} - - {{ .Site.Params.promoAnnouncementText }} → - - {{ end }} + {{ 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 0000000..5ce3172 --- /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 0000000..b3f7067 --- /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 0000000..c382df1 --- /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 0000000..2c375c3 --- /dev/null +++ b/static/site-banner/theme.css @@ -0,0 +1,7 @@ +.site-banner { + --site-banner-bg: var(--primary-button-background-color, #00aaff); + --site-banner-text: var(--primary-background-color, #0015a7); + --site-banner-button: var(--primary-background-color, #0015a7); + --site-banner-button-text: #ffffff; + --site-banner-gutter: 16px; +}