diff --git a/apps/board/tests/test_templates.py b/apps/board/tests/test_templates.py index 7134455..3c1fa49 100644 --- a/apps/board/tests/test_templates.py +++ b/apps/board/tests/test_templates.py @@ -388,3 +388,48 @@ def test_the_public_agenda_draws_every_day_on_a_phone_too(): assert weekday and weekday[2] != "none", ( "the phone block never shows .agenda__weekday, so every row of the " "month is a bare number — there is no column header at that width") + + +# --- the share row, which is theme and not members area -------------------- + +def test_the_share_buttons_that_need_a_script_say_so_in_the_markup(): + """Three of the seven cannot be links: Signal has no web intent, Instagram + accepts no URL at all, and copying needs the clipboard. They carry `hidden` + and share.js takes it off — so a reader without scripting sees four buttons + that work rather than seven of which three do nothing. + """ + share = (THEME / "layouts" / "partials" / "share.html").read_text(encoding="utf-8") + for hook in ("data-share-native", "data-share-copy"): + for element in re.findall(r"<(?:a|button)[^>]*" + hook + r"[^>]*>", share): + assert "hidden" in element, f"{hook} without `hidden`: {element[:80]}" + + +def test_a_hidden_share_button_is_actually_hidden(): + """`[hidden] { display: none }` lives in the browser's own stylesheet, and + an author rule beats a user-agent rule whatever the specificity — so + `.share__btn { display: inline-flex }` quietly un-hid all three. With + scripting off, seven buttons appeared and three of them did nothing, which + is the exact failure the attribute was there to prevent. + """ + css = (THEME / "assets" / "css" / "main.css").read_text(encoding="utf-8") + assert re.search(r"\.share__btn\[hidden\]\s*\{[^}]*display:\s*none", css), ( + "main.css gives .share__btn a display without taking it back for " + "[hidden], so the buttons share.js is meant to reveal are visible " + "before it runs — and useless until it does") + + +def test_every_share_link_is_marked_safe_so_it_is_not_encoded_twice(): + """Go's template escaper treats an href as a URL and escapes it on the way + out. A value already encoded with `urlquery` therefore went out as %253A + and %2b — a WhatsApp link with the percent signs spelled out, which opens + the composer with gibberish in it. `safeURL` is what stops the second pass. + """ + share = (THEME / "layouts" / "partials" / "share.html").read_text(encoding="utf-8") + # By line rather than by matching the attribute: the value contains its own + # quotes — `href="{{ printf "https://…" $enc | safeURL }}"` — and a regex + # for href="..." stops at the first of them and reads nothing. + lines = [line.strip() for line in share.splitlines() + if "href=" in line and "$enc" in line] + assert lines, "share.html builds no encoded links at all any more" + for line in lines: + assert "safeURL" in line, f"encoded twice: {line}" diff --git a/config.yaml b/config.yaml index 9e869ff..33ac3a0 100644 --- a/config.yaml +++ b/config.yaml @@ -135,3 +135,35 @@ markup: unsafe: false enableRobotsTXT: false # robots.txt is a static file in static/ + +# The uploads are mounted twice on purpose. +# +# Hugo copies `static/` and processes `assets/`, and a picture that is only +# copied cannot be resized — which is why a share card used to point at the +# original: a photograph off a phone, two to five megabytes. WhatsApp fetches a +# preview image on a tight budget and gives up on a file that size, so the card +# arrived with a blank where the picture should be. +# +# Mounting `static/uploads` into `assets/uploads` as well lets seo-head.html +# build a 1200×630 card from the same file, while the static copy stays exactly +# where it is: every existing /uploads/… URL, every image in every post, and +# everything the editor commits are untouched. +# +# Declaring any mount means declaring them all — these five are Hugo's own +# defaults, written out so nothing silently stops being read. +module: + mounts: + - source: content + target: content + - source: layouts + target: layouts + - source: data + target: data + - source: assets + target: assets + - source: static + target: static + - source: static/uploads + target: assets/uploads + - source: static/brand + target: assets/brand diff --git a/docs/server-setup.md b/docs/server-setup.md index 8f34dc9..e561330 100644 --- a/docs/server-setup.md +++ b/docs/server-setup.md @@ -1080,9 +1080,8 @@ card and `BlogPosting` for articles. What it now also does: - **Static pages get all of it** — they had none, so *Acerca de* shared as a bare link. `WebPage` schema, Open Graph, the card -- **`og:image` with an alt**, from the post's own picture or `params.defaultImage` - as a fallback. That param is empty: fill it in when there is a logo, and every - link shared on WhatsApp, Signal, Mastodon or Bluesky starts carrying a picture +- **`og:image` with an alt**, built rather than pointed at — see §11.16b, which + is the difference between a card with a picture and a card without one - **`Organization`** on the home, with `areaServed: Wien` and a `sameAs` list ready for social profiles — this is how a search or answer engine knows the Instagram account and this site are one body @@ -1098,6 +1097,63 @@ The translation pipeline carries all of it: `image_alt` joins the translated keys, and `faq` is translated line by line with each half handled separately so the `|` survives. +### 11.16b The share row, and the card that arrives + +**Seven buttons under the title of every post and again after the text**, from +`partials/share.html`. Four are ordinary links and work with scripting off: +WhatsApp, Facebook, Bluesky and Mastodon all accept a URL that opens their own +composer. + +The other three cannot be links, and it is worth knowing why rather than +rediscovering it: + +| | | +|---|---| +| **Signal** | has no web intent at all. It is a share *target* in the operating system's own sheet and nowhere else | +| **Instagram** | accepts no link from anybody, by design. Every site with an Instagram share button is really offering a copied link | +| **Copiar enlace** | the fallback for everything the two above do not cover, including a desktop with no share sheet | + +All three call `navigator.share()` where it exists and copy the address where it +does not. They carry `hidden` in the markup and `share.js` removes it, so a +reader without scripting sees four buttons that work rather than seven of which +three do nothing. `main.css` has to say `.share__btn[hidden] { display: none }` +explicitly: `[hidden]` lives in the browser's own stylesheet and an author rule +beats it whatever the specificity, so `display: inline-flex` silently un-hid all +three the first time. + +Mastodon has no central address — the composer lives on whichever server the +*reader* has an account on. The button asks once, keeps the answer in +`localStorage`, and without scripting falls back to the association's own server +from *Gestión → Identidad* when one is set. + +The links are built with `urlquery` **and** marked `safeURL`. Go's template +escaper treats an href as a URL and escapes it again on the way out, so without +that the WhatsApp link went out as `%253A` and `%2b` — the composer opening with +the percent signs spelled out. + +**The card image is generated, not linked.** This is the half that was actually +broken: `og:image` pointed at the original upload, a photograph off a phone of +two to five megabytes, and WhatsApp fetches preview images on a tight budget and +gives up on a file that size — so the card arrived as a title and a link with a +blank where the picture should be. + +Hugo copies `static/` and processes `assets/`, and only the second can be +resized, so `config.yaml` mounts `static/uploads` and `static/brand` into +`assets/` **as well**. The static copies stay exactly where they are: every +`/uploads/…` URL, every image in every post and everything the editor commits +are untouched. `seo-head.html` then fills a post's photograph to **1200×630** +(80–150 KB in practice, measured at 93 KB against a 22 MB source) and fits the +logo fallback without cropping — a wordmark filled to a landscape card loses its +ends, and converting a transparent PNG to JPEG puts it on a black square. + +`partials/og-image.html` emits the five tags together, including +`og:image:width` and `og:image:height`, which are not decoration: several +clients draw the small card rather than the large one when they would have to +fetch the file to find out how big it is. + +A picture the pipeline cannot find falls back to the absolute URL with no +dimensions — exactly what happened before, so nothing is ever worse than it was. + ### 11.17 Writing boxes Every box where somebody writes prose — the wall, a comment, a private message, a diff --git a/themes/vienalatina/assets/css/main.css b/themes/vienalatina/assets/css/main.css index 66663ef..196e7d5 100644 --- a/themes/vienalatina/assets/css/main.css +++ b/themes/vienalatina/assets/css/main.css @@ -4150,3 +4150,100 @@ a.notif-card__message:hover { letter-spacing: 0.02em; vertical-align: middle; } + +/* --- sharing ------------------------------------------------------------ + * + * A tinted strip rather than six bare icons: the row has to be noticed to be + * used, and a label saying what it is costs one word. Drawn twice on a post — + * under the title and after the text — so it meets both the reader who decides + * on sight and the one who decides at the end. + * + * Each button takes its own brand colour on hover and keeps the page's muted + * grey at rest, so the row reads as one object instead of six logos competing + * with the article. + */ +.share { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 8px; + margin: 18px 0 24px; + padding: 10px 14px; + border: 1px solid var(--border-light, #e0cec8); + border-radius: var(--radius-lg, 14px); + background: var(--surface-soft, #faf2ef); +} + +.share__title { + font-size: 0.85rem; + font-weight: 700; + color: var(--muted, #5c3d37); + margin-right: 4px; +} + +.share__btn { + display: inline-flex; + align-items: center; + justify-content: center; + width: 38px; + height: 38px; + padding: 0; + border: 1px solid var(--border-light, #e0cec8); + border-radius: 50%; + background: var(--surface, #fff); + color: var(--muted, #5c3d37); + cursor: pointer; + transition: color 120ms ease, border-color 120ms ease, transform 120ms ease; +} +.share__btn svg { width: 20px; height: 20px; fill: currentColor; } +.share__btn:hover { transform: translateY(-1px); } + +/* The `hidden` attribute, given back its meaning. + * + * `[hidden] { display: none }` lives in the browser's own stylesheet, and an + * author rule beats a user-agent rule whatever the specificity — so the + * `display: inline-flex` above quietly un-hid the three buttons that are + * supposed to appear only once share.js has run. With scripting off, all + * seven showed and three of them did nothing at all, which is the exact + * failure the attribute was there to prevent. */ +.share__btn[hidden] { display: none; } + +/* Their own colours, and only on hover: at rest the row belongs to the page. */ +.share__btn--whatsapp:hover { color: #25d366; border-color: #25d366; } +.share__btn--facebook:hover { color: #1877f2; border-color: #1877f2; } +.share__btn--bluesky:hover { color: #0085ff; border-color: #0085ff; } +.share__btn--mastodon:hover { color: #6364ff; border-color: #6364ff; } +.share__btn--signal:hover { color: #3a76f0; border-color: #3a76f0; } +.share__btn--instagram:hover { color: #e1306c; border-color: #e1306c; } +.share__btn--copy:hover { color: var(--brand, #c0391c); border-color: var(--brand, #c0391c); } + +.share__btn:focus-visible { + outline: 2px solid var(--brand, #c0391c); + outline-offset: 2px; +} + +/* The name is for a screen reader and for `title` on a cursor; the icon is for + everybody else. Hidden this way rather than with display:none, which would + take it out of the accessibility tree along with the button's only label. */ +.share__name { + position: absolute; + width: 1px; + height: 1px; + margin: -1px; + padding: 0; + overflow: hidden; + clip-path: inset(50%); + white-space: nowrap; +} + +/* What the copy button says back. Empty until it has something to say, so it + takes no room on a row that is already seven items wide. */ +.share__said { + font-size: 0.8rem; + color: var(--brand-dark, #9a2a0f); + font-weight: 600; +} + +@media (pointer: coarse) { + .share__btn { width: 44px; height: 44px; } +} diff --git a/themes/vienalatina/assets/js/share.js b/themes/vienalatina/assets/js/share.js new file mode 100644 index 0000000..8445647 --- /dev/null +++ b/themes/vienalatina/assets/js/share.js @@ -0,0 +1,116 @@ +// The three share buttons that cannot be plain links. +// +// WhatsApp, Facebook, Bluesky and Mastodon all accept a URL that opens their +// own composer, so those are anchors in share.html and work with this file +// absent. These three cannot be: +// +// Signal has no web intent at all. It is a share *target* in the +// operating system's own sheet and nowhere else. +// Instagram accepts no link from anybody, by design. Every site with an +// Instagram share button is really offering a copied link. +// Copiar is the fallback for every case the two above do not cover, +// including a desktop with no share sheet. +// +// All three are `hidden` in the markup and shown here, so a reader without +// scripting sees four buttons that work rather than seven of which three do +// nothing. + +(function () { + "use strict"; + + function copy(text) { + if (navigator.clipboard && navigator.clipboard.writeText) { + return navigator.clipboard.writeText(text); + } + // Older engines, and any page not served over https: a textarea, selected + // and copied the way it was done before the clipboard API existed. + return new Promise(function (resolve, reject) { + var box = document.createElement("textarea"); + box.value = text; + box.setAttribute("readonly", ""); + box.style.position = "fixed"; + box.style.opacity = "0"; + document.body.appendChild(box); + box.select(); + try { + document.execCommand("copy") ? resolve() : reject(); + } catch (error) { + reject(error); + } + document.body.removeChild(box); + }); + } + + function wire(row) { + var url = row.getAttribute("data-url"); + var title = row.getAttribute("data-title"); + var text = row.getAttribute("data-text"); + var said = row.querySelector(".share__said"); + + function announce(message) { + if (!said) { return; } + said.textContent = message; + window.setTimeout(function () { said.textContent = ""; }, 2500); + } + + function copyAndSay() { + copy(url).then(function () { + announce(row.getAttribute("data-copied")); + }).catch(function () { + // Copying can be refused outright — a permission, an engine without + // either route. Saying nothing would look like a button that does + // nothing, so the address is put on screen to be copied by hand. + announce(url); + }); + } + + // Signal and Instagram: the operating system's sheet, which lists both + // when they are installed. There is no way to open one app in particular, + // and pretending otherwise is what a broken button is made of. + Array.prototype.forEach.call(row.querySelectorAll("[data-share-native]"), function (button) { + button.hidden = false; + button.addEventListener("click", function () { + if (navigator.share) { + navigator.share({ title: title, text: text, url: url }).catch(function () { + // Dismissed, which is not a failure and needs no message. + }); + } else { + copyAndSay(); + } + }); + }); + + Array.prototype.forEach.call(row.querySelectorAll("[data-share-copy]"), function (button) { + button.hidden = false; + button.addEventListener("click", copyAndSay); + }); + + // Mastodon has no central address: the composer lives on whichever server + // the *reader* has an account on. Asked once and kept, because asking on + // every post would be worse than not offering it. + var masto = row.querySelector("[data-share-mastodon]"); + if (masto) { + masto.hidden = false; + masto.addEventListener("click", function (event) { + var saved = null; + try { saved = window.localStorage.getItem("vl-mastodon"); } catch (error) { saved = null; } + var host = saved || window.prompt(row.getAttribute("data-ask"), "mastodon.social"); + if (!host) { + // Nothing typed: fall through to the association's own server when + // the markup had one, and otherwise do nothing at all. + if (masto.getAttribute("href") === "#") { event.preventDefault(); } + return; + } + host = host.trim().replace(/^https?:\/\//, "").replace(/\/.*$/, ""); + if (!host) { event.preventDefault(); return; } + try { window.localStorage.setItem("vl-mastodon", host); } catch (error) { /* private window */ } + masto.setAttribute("href", + "https://" + host + "/share?text=" + encodeURIComponent(text)); + }); + } + } + + document.addEventListener("DOMContentLoaded", function () { + Array.prototype.forEach.call(document.querySelectorAll("[data-share]"), wire); + }); +})(); diff --git a/themes/vienalatina/layouts/_default/single.html b/themes/vienalatina/layouts/_default/single.html index 741a284..8f84b19 100644 --- a/themes/vienalatina/layouts/_default/single.html +++ b/themes/vienalatina/layouts/_default/single.html @@ -41,6 +41,11 @@