Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="http://localhost:1313/404.html">/404.html</a>.

## 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=<ISO 8601 time>` (for example `?banner-time=2026-12-01T18:00:00Z`) or `?banner=<id>` previews the schedule. The live site ignores both.
25 changes: 25 additions & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
7 changes: 0 additions & 7 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<!DOCTYPE html>
<html lang="{{ site.Language.Lang }}" class="tpl-page">
{{ partial "head.html" . }} {{ partial "header.html" . }}
{{ if .Site.Params.site_banner_enabled }}
{{ if .Site.Params.site_banner_text }}
<div id="site-banner">
<a href="{{ .Site.Params.site_banner_href }}">{{ .Site.Params.site_banner_text }} →</a>
</div>
{{ end }}
{{ end }}
<div class="container-fluid pb-6">
<div class="row">
<div class="col-md-8 offset-md-2">
Expand Down
7 changes: 0 additions & 7 deletions layouts/blog/baseof.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<!DOCTYPE html>
<html lang="{{ site.Language.Lang }}" class="tpl-post">
{{ partial "head.html" . }} {{ partial "header.html" . }}
{{ if .Site.Params.site_banner_enabled }}
{{ if .Site.Params.site_banner_text }}
<div id="site-banner">
<a href="{{ .Site.Params.site_banner_href }}">{{ .Site.Params.site_banner_text }} →</a>
</div>
{{ end }}
{{ end }}
<div class="container-fluid pb-6">
<div class="row">
<div class="col-md-8 offset-md-2">
Expand Down
8 changes: 0 additions & 8 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ <h3>for the Internet's most critical infrastructure</h3>
</div>
</section>

{{ if .Site.Params.site_banner_enabled }}
{{ if .Site.Params.site_banner_text }}
<div id="site-banner">
<a href="{{ .Site.Params.site_banner_href }}">{{ .Site.Params.site_banner_text }} →</a>
</div>
{{ end }}
{{ end }}

<div class="container mt-5">
<div class="row">
<section class="col-md-7 pr-2 home-initiatives" id="initiatives">
Expand Down
7 changes: 0 additions & 7 deletions layouts/initiative/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
{{ partial "head.html" . }} {{ partial "header.html" . }}
<span></span>
{{ partial "initiative/initiative_hero.html" .}}
{{ if .Site.Params.site_banner_enabled }}
{{ if .Site.Params.site_banner_text }}
<div id="site-banner" class="mb-3 mb-md-5">
<a href="{{ .Site.Params.site_banner_href }}">{{ .Site.Params.site_banner_text }} →</a>
</div>
{{ end }}
{{ end }}


<div class="container page-content">
Expand Down
1 change: 1 addition & 0 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@
</nav>
</div>
</header>
{{ partial "site-banner.html" (dict "page" . "container" "container px-0 px-xl-3") }}
21 changes: 21 additions & 0 deletions layouts/partials/site-banner.html
Original file line number Diff line number Diff line change
@@ -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 }}
<link rel="stylesheet" href="{{ "site-banner/site-banner.css" | relURL }}?v={{ readFile "static/site-banner/site-banner.css" | md5 }}">
<link rel="stylesheet" href="{{ "site-banner/theme.css" | relURL }}?v={{ readFile "static/site-banner/theme.css" | md5 }}">
<aside class="site-banner" aria-label="Announcement" data-site-banner="{{ $config | jsonify }}" hidden>
<div class="{{ .container }}">
<div class="site-banner__inner">
<p class="site-banner__message"></p>
<a class="site-banner__cta" hidden></a>
<button class="site-banner__close" type="button" aria-label="Dismiss banner"><svg aria-hidden="true" focusable="false" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="m5 5 14 14M19 5 5 19" /></svg></button>
</div>
</div>
</aside>
<script src="{{ "site-banner/site-banner.js" | relURL }}?v={{ readFile "static/site-banner/site-banner.js" | md5 }}" defer></script>
{{ end }}
85 changes: 85 additions & 0 deletions static/site-banner/site-banner.css
Original file line number Diff line number Diff line change
@@ -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; }
}
85 changes: 85 additions & 0 deletions static/site-banner/site-banner.js
Original file line number Diff line number Diff line change
@@ -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=<ISO 8601 time> or ?banner=<id> 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();
})();
7 changes: 7 additions & 0 deletions static/site-banner/theme.css
Original file line number Diff line number Diff line change
@@ -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;
}
Loading