Compare commits
7 Commits
d49cab8786
...
1556ad26d7
| Author | SHA1 | Date | |
|---|---|---|---|
| 1556ad26d7 | |||
| 6a591890f6 | |||
|
|
790bd2230f | ||
| b5a17f3505 | |||
|
|
0d2e590c5a | ||
| ec6bd671f2 | |||
|
|
cba9939eb2 |
19
README.md
19
README.md
@ -234,15 +234,12 @@ a file it cannot parse publishes in Spanish and is never translated, silently.
|
|||||||
- `llms.txt` — generated at build time from `layouts/index.llms.txt`
|
- `llms.txt` — generated at build time from `layouts/index.llms.txt`
|
||||||
- `sitemap.xml` — Hugo native, multilingual
|
- `sitemap.xml` — Hugo native, multilingual
|
||||||
|
|
||||||
## One-shot content migration
|
## The site this replaced
|
||||||
|
|
||||||
```sh
|
The content came from a WordPress install, once, with a disposable script that
|
||||||
pip install requests html2text
|
has been deleted along with it. What remains of that site is a handful of 301s
|
||||||
python scripts/wp-to-hugo.py https://<old-wp-site>
|
in `infra/caddy/Caddyfile` — old permalinks, `/categoria/…`, author archives
|
||||||
```
|
and the WordPress media library — so links shared before the cutover still
|
||||||
|
land somewhere. Everything beginning with `/wp-` answers with a redirect home
|
||||||
Converts every WP post (with Polylang siblings) to
|
rather than reaching the members area, which is where `/wp-cron.php` used to
|
||||||
`content/post/<slug>.<lang>.md`, downloads images into `static/uploads/`,
|
end up.
|
||||||
and preserves existing slugs. Spot-check ~10 articles before committing.
|
|
||||||
Add Caddy 301s for WP URL patterns that don't map cleanly
|
|
||||||
(`?p=123`, `/categoria/...` → `/categories/...`).
|
|
||||||
|
|||||||
@ -388,3 +388,48 @@ def test_the_public_agenda_draws_every_day_on_a_phone_too():
|
|||||||
assert weekday and weekday[2] != "none", (
|
assert weekday and weekday[2] != "none", (
|
||||||
"the phone block never shows .agenda__weekday, so every row of the "
|
"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")
|
"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}"
|
||||||
|
|||||||
32
config.yaml
32
config.yaml
@ -135,3 +135,35 @@ markup:
|
|||||||
unsafe: false
|
unsafe: false
|
||||||
|
|
||||||
enableRobotsTXT: false # robots.txt is a static file in static/
|
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
|
||||||
|
|||||||
@ -39,16 +39,34 @@ Check propagation (repeat until it prints the server IP):
|
|||||||
local$ dig +short git.vienalatina.com
|
local$ dig +short git.vienalatina.com
|
||||||
```
|
```
|
||||||
|
|
||||||
### 1.1 A second domain that leads here
|
### 1.1 The other two domains
|
||||||
|
|
||||||
`vielac.at` is the second name, and it redirects: everything that arrives goes
|
`vielac.at` is where the WordPress site this project replaced used to live;
|
||||||
to the same path on vienalatina.com. Two A records in that domain's **zone
|
`vienalatina.net` is the .com's sibling. Both redirect: everything that arrives
|
||||||
editor**, both at the server:
|
goes to the same path on vienalatina.com, where the 301s for old WordPress paths
|
||||||
|
catch it. Pointing them here is also what takes the last traffic off the old box.
|
||||||
|
|
||||||
| Name | Type | Value | TTL |
|
In **each** of those two zones, four rows change and **nothing else**:
|
||||||
|
|
||||||
|
| Name | Type | Was | Becomes |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| `@` | A | `<SERVER-IP>` | 300 |
|
| `@` | A | the old box | `<SERVER-IP>`, TTL 300 |
|
||||||
| `www` | A | `<SERVER-IP>` | 300 |
|
| `www` | A | the old box | `<SERVER-IP>`, TTL 300 |
|
||||||
|
| `@` | AAAA | the old box's IPv6 | **deleted** |
|
||||||
|
| `www` | AAAA | the old box's IPv6 | **deleted** |
|
||||||
|
|
||||||
|
**The AAAA rows are the trap.** A browser with IPv6 prefers it to IPv4, so
|
||||||
|
leaving them behind means the A records change, the old site keeps appearing,
|
||||||
|
and nothing on screen explains why. Delete them unless this server has an IPv6
|
||||||
|
address of its own (`ip -6 addr show scope global`), in which case use that.
|
||||||
|
|
||||||
|
**Leave the mail rows exactly as they are** — `MX`, the four `SRV`s, `CNAME
|
||||||
|
autoconfig`, the SPF `TXT`, and the DKIM `TXT` that vienalatina.net carries.
|
||||||
|
They point at Hetzner's mail server and have nothing to do with which machine
|
||||||
|
serves the website. **And never copy** `NS` or `SOA` between zones (every zone
|
||||||
|
has its own), nor the `ci` and `git` A rows, which are vienalatina.com
|
||||||
|
subdomains with their own site blocks: a `git.vielac.at` would resolve here,
|
||||||
|
find no block, and fail the TLS handshake.
|
||||||
|
|
||||||
**Not the nameserver page.** On Hetzner's Konsole H those fields hand the whole
|
**Not the nameserver page.** On Hetzner's Konsole H those fields hand the whole
|
||||||
zone to another provider's DNS, which is a different thing entirely and turns
|
zone to another provider's DNS, which is a different thing entirely and turns
|
||||||
@ -76,13 +94,17 @@ sudo systemctl reload caddy
|
|||||||
between a typo in that file and vienalatina.com going down with it.
|
between a typo in that file and vienalatina.com going down with it.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
dig +short vielac.at A vienalatina.net A # both: this server
|
||||||
|
dig +short vielac.at AAAA vienalatina.net AAAA # nothing at all
|
||||||
curl -sI https://vielac.at/ | head -3 # 301 → vienalatina.com
|
curl -sI https://vielac.at/ | head -3 # 301 → vienalatina.com
|
||||||
curl -sI https://www.vielac.at/page/agenda/ | grep -i location # the path survives
|
curl -sI https://www.vienalatina.net/page/agenda/ | grep -i location # the path survives
|
||||||
curl -sI https://vienalatina.com/ | head -1 # 200, unchanged
|
curl -sI https://vienalatina.com/ | head -1 # 200, unchanged
|
||||||
|
dig +short vienalatina.com MX # mail, still answering
|
||||||
```
|
```
|
||||||
|
|
||||||
The third is the one that matters. A Caddyfile edit that breaks the site it was
|
The last two are the ones that matter. A Caddyfile edit that breaks the site it
|
||||||
meant to leave alone is the failure this ordering exists to prevent.
|
was meant to leave alone, or a DNS session across three zones that takes the
|
||||||
|
mailbox with it, are the two failures this ordering exists to prevent.
|
||||||
|
|
||||||
## 2. First login + basic hardening
|
## 2. First login + basic hardening
|
||||||
|
|
||||||
@ -1058,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
|
- **Static pages get all of it** — they had none, so *Acerca de* shared as a bare
|
||||||
link. `WebPage` schema, Open Graph, the card
|
link. `WebPage` schema, Open Graph, the card
|
||||||
- **`og:image` with an alt**, from the post's own picture or `params.defaultImage`
|
- **`og:image` with an alt**, built rather than pointed at — see §11.16b, which
|
||||||
as a fallback. That param is empty: fill it in when there is a logo, and every
|
is the difference between a card with a picture and a card without one
|
||||||
link shared on WhatsApp, Signal, Mastodon or Bluesky starts carrying a picture
|
|
||||||
- **`Organization`** on the home, with `areaServed: Wien` and a `sameAs` list
|
- **`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
|
ready for social profiles — this is how a search or answer engine knows the
|
||||||
Instagram account and this site are one body
|
Instagram account and this site are one body
|
||||||
@ -1076,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
|
keys, and `faq` is translated line by line with each half handled separately so
|
||||||
the `|` survives.
|
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
|
### 11.17 Writing boxes
|
||||||
|
|
||||||
Every box where somebody writes prose — the wall, a comment, a private message, a
|
Every box where somebody writes prose — the wall, a comment, a private message, a
|
||||||
|
|||||||
@ -21,19 +21,25 @@ www.vienalatina.com {
|
|||||||
redir https://vienalatina.com{uri} 301
|
redir https://vienalatina.com{uri} 301
|
||||||
}
|
}
|
||||||
|
|
||||||
# The second name, which leads here rather than somewhere else.
|
# The other names the association answers to. vielac.at is where the WordPress
|
||||||
|
# install this project replaced used to live — it is the address in every link
|
||||||
|
# shared before the cutover, in every search result not yet recrawled, and in
|
||||||
|
# the bookmarks of everybody who read it. vienalatina.net is the .com's sibling.
|
||||||
#
|
#
|
||||||
# Both spellings in one block, and 301 rather than 302: a permanent redirect is
|
# All four spellings in one block, and 301 rather than 302: a permanent redirect
|
||||||
# what makes a search engine fold the two names into one site instead of
|
# is what makes a search engine fold them into one site instead of indexing four
|
||||||
# indexing them as duplicates of each other, and what makes a browser stop
|
# copies of each other, and what makes a browser stop asking after the first
|
||||||
# asking after the first visit. `{uri}` carries the path, so a link somebody
|
# visit. `{uri}` carries the path, so a link somebody shared to
|
||||||
# shared to vielac.at/page/agenda/ lands on the agenda rather than on the home
|
# vielac.at/page/agenda/ lands on the agenda rather than on the home page — and
|
||||||
# page.
|
# an old WordPress path arrives at vienalatina.com and is caught by the 301s
|
||||||
|
# further down, which is one set of rules rather than three.
|
||||||
#
|
#
|
||||||
# Caddy asks Let's Encrypt for this certificate the first time the name
|
# Caddy asks Let's Encrypt for each certificate the first time that name
|
||||||
# resolves to this server, so the A records go in before this file is reloaded.
|
# resolves to this server, so this block can be deployed while the names still
|
||||||
# Until they do, the block is harmless: nothing reaches it.
|
# point elsewhere: nothing reaches it until they move, and when they do the
|
||||||
vielac.at, www.vielac.at {
|
# certificate is fetched on the first request rather than after a second trip
|
||||||
|
# to the server.
|
||||||
|
vielac.at, www.vielac.at, vienalatina.net, www.vienalatina.net {
|
||||||
redir https://vienalatina.com{uri} 301
|
redir https://vienalatina.com{uri} 301
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,9 +104,11 @@ vienalatina.com {
|
|||||||
}
|
}
|
||||||
redir @wp_query_permalink / 301
|
redir @wp_query_permalink / 301
|
||||||
|
|
||||||
# WP category base was /categoria/… (Spanish slugs); Hugo uses /categories/…
|
# The old category base, which now has nowhere to land: the taxonomy was
|
||||||
|
# removed from this site, so /categories/… is a 404 and a 301 into it would
|
||||||
|
# be sending somebody from one dead address to another. Home instead.
|
||||||
@old_category path_regexp oldcat ^/categoria/(.*)$
|
@old_category path_regexp oldcat ^/categoria/(.*)$
|
||||||
redir @old_category /categories/{re.oldcat.1} 301
|
redir @old_category / 301
|
||||||
|
|
||||||
# WP author archives have no Hugo equivalent → home
|
# WP author archives have no Hugo equivalent → home
|
||||||
@old_author path /autor/*
|
@old_author path /autor/*
|
||||||
@ -110,8 +118,18 @@ vienalatina.com {
|
|||||||
@old_uploads path_regexp oldup ^/wp-content/uploads/(?:\d{4}/\d{2}/)?(.*)$
|
@old_uploads path_regexp oldup ^/wp-content/uploads/(?:\d{4}/\d{2}/)?(.*)$
|
||||||
redir @old_uploads /uploads/{re.oldup.1} 301
|
redir @old_uploads /uploads/{re.oldup.1} 301
|
||||||
|
|
||||||
# Anything else that starts with /wp- doesn't exist anymore
|
# Anything else beginning with /wp- is gone. Written as a wildcard rather
|
||||||
@wp_leftovers path /wp-admin/* /wp-login.php /wp-json/* /xmlrpc.php
|
# than a list, because the list was missing the one that mattered:
|
||||||
|
# /wp-cron.php fell through to the single-segment profile matcher below —
|
||||||
|
# it looks exactly like a member's name — reached the Flask app, and was
|
||||||
|
# answered with a 400 by the CSRF hook. A WordPress install elsewhere was
|
||||||
|
# POSTing it every few minutes, so the members area was being woken up by
|
||||||
|
# the site it replaced.
|
||||||
|
#
|
||||||
|
# After the uploads rule above, never before it: these are `redir`
|
||||||
|
# directives and Caddy keeps them in the order they are written, so
|
||||||
|
# /wp-content/uploads/… still maps to the migrated pictures.
|
||||||
|
@wp_leftovers path /wp-* /xmlrpc.php
|
||||||
redir @wp_leftovers / 301
|
redir @wp_leftovers / 301
|
||||||
|
|
||||||
# Custom 404 falls back to Hugo's 404 page
|
# Custom 404 falls back to Hugo's 404 page
|
||||||
|
|||||||
@ -1,155 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""One-shot WordPress → Hugo content migration (disposable).
|
|
||||||
|
|
||||||
Pulls every post from the WP REST API (with Polylang language codes),
|
|
||||||
converts HTML bodies to Markdown, downloads images into static/uploads/,
|
|
||||||
rewrites their URLs, and writes content/post/<slug>.<lang>.md files whose
|
|
||||||
basenames pair Polylang siblings the way Hugo expects.
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
pip install requests html2text
|
|
||||||
python scripts/wp-to-hugo.py https://vielac.at
|
|
||||||
|
|
||||||
Existing Spanish slugs are preserved so inbound links keep resolving after
|
|
||||||
the DNS cutover (add Caddy 301s for anything that doesn't map cleanly).
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
import html2text
|
|
||||||
import requests
|
|
||||||
|
|
||||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
||||||
POSTS_DIR = REPO_ROOT / "content" / "post"
|
|
||||||
UPLOADS_DIR = REPO_ROOT / "static" / "uploads"
|
|
||||||
|
|
||||||
# Polylang slug -> Hugo language slug used in filenames.
|
|
||||||
LANG_MAP = {"es": "es", "de": "de", "pt-br": "pt-br", "pt": "pt-br"}
|
|
||||||
|
|
||||||
|
|
||||||
def fetch_all(base_url: str, endpoint: str) -> list[dict]:
|
|
||||||
items, page = [], 1
|
|
||||||
while True:
|
|
||||||
resp = requests.get(
|
|
||||||
f"{base_url}/wp-json/wp/v2/{endpoint}",
|
|
||||||
params={"per_page": 100, "page": page, "_embed": "1", "lang": ""},
|
|
||||||
timeout=30,
|
|
||||||
)
|
|
||||||
if resp.status_code == 400: # past the last page
|
|
||||||
break
|
|
||||||
resp.raise_for_status()
|
|
||||||
batch = resp.json()
|
|
||||||
if not batch:
|
|
||||||
break
|
|
||||||
items.extend(batch)
|
|
||||||
if page >= int(resp.headers.get("X-WP-TotalPages", 1)):
|
|
||||||
break
|
|
||||||
page += 1
|
|
||||||
return items
|
|
||||||
|
|
||||||
|
|
||||||
def download_image(url: str) -> str:
|
|
||||||
"""Fetch a WP upload into static/uploads/, return its new site-relative URL."""
|
|
||||||
name = Path(urlparse(url).path).name
|
|
||||||
if not name:
|
|
||||||
return url
|
|
||||||
dest = UPLOADS_DIR / name
|
|
||||||
if not dest.exists():
|
|
||||||
resp = requests.get(url, timeout=30)
|
|
||||||
if resp.status_code != 200:
|
|
||||||
print(f" ! image fetch failed ({resp.status_code}): {url}")
|
|
||||||
return url
|
|
||||||
UPLOADS_DIR.mkdir(parents=True, exist_ok=True)
|
|
||||||
dest.write_bytes(resp.content)
|
|
||||||
return f"/uploads/{name}"
|
|
||||||
|
|
||||||
|
|
||||||
def rewrite_images(html: str, base_url: str) -> str:
|
|
||||||
pattern = re.escape(base_url.rstrip("/")) + r"/wp-content/uploads/[^\s\"'<>)]+"
|
|
||||||
return re.sub(pattern, lambda m: download_image(m.group(0)), html)
|
|
||||||
|
|
||||||
|
|
||||||
def to_markdown(html: str) -> str:
|
|
||||||
conv = html2text.HTML2Text()
|
|
||||||
conv.body_width = 0
|
|
||||||
conv.protect_links = True
|
|
||||||
return conv.handle(html).strip()
|
|
||||||
|
|
||||||
|
|
||||||
def frontmatter(post: dict, lang: str, categories: dict[int, str],
|
|
||||||
derived_from: str | None = None) -> str:
|
|
||||||
title = to_markdown(post["title"]["rendered"]).replace('"', '\\"')
|
|
||||||
cats = [categories[c] for c in post.get("categories", []) if c in categories]
|
|
||||||
lines = [
|
|
||||||
"---",
|
|
||||||
f'title: "{title}"',
|
|
||||||
f"date: {post['date']}",
|
|
||||||
f"slug: {post['slug']}", # preserve the exact WP slug per language
|
|
||||||
f"lang: {lang}",
|
|
||||||
]
|
|
||||||
if derived_from:
|
|
||||||
# A Polylang sibling: derived, so translate.py never treats it as a
|
|
||||||
# source — and frozen, because these are *human* WordPress translations
|
|
||||||
# and regenerating them would replace them with weaker machine output.
|
|
||||||
lines.extend([f"translated_from: {derived_from}", "manual_translation: true"])
|
|
||||||
else:
|
|
||||||
lines.append("manual_translation: false")
|
|
||||||
lines.append(f"categories: [{', '.join(cats)}]")
|
|
||||||
excerpt = to_markdown(post.get("excerpt", {}).get("rendered", ""))
|
|
||||||
if excerpt:
|
|
||||||
lines.append(f'description: "{excerpt[:300].replace(chr(34), chr(39))}"')
|
|
||||||
embedded = post.get("_embedded", {}).get("wp:featuredmedia", [])
|
|
||||||
if embedded and embedded[0].get("source_url"):
|
|
||||||
lines.append(f"image: {download_image(embedded[0]['source_url'])}")
|
|
||||||
lines.append("---")
|
|
||||||
return "\n".join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
if len(sys.argv) != 2:
|
|
||||||
sys.exit("Usage: python scripts/wp-to-hugo.py https://your-wp-site.example")
|
|
||||||
base_url = sys.argv[1].rstrip("/")
|
|
||||||
|
|
||||||
categories = {c["id"]: c["name"] for c in fetch_all(base_url, "categories")}
|
|
||||||
posts = fetch_all(base_url, "posts")
|
|
||||||
print(f"Fetched {len(posts)} posts, {len(categories)} categories.")
|
|
||||||
|
|
||||||
by_id = {p["id"]: p for p in posts}
|
|
||||||
POSTS_DIR.mkdir(parents=True, exist_ok=True)
|
|
||||||
written = 0
|
|
||||||
|
|
||||||
for post in posts:
|
|
||||||
lang = LANG_MAP.get(post.get("lang", "es"))
|
|
||||||
if not lang:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Polylang exposes sibling IDs in `translations`; use the Spanish
|
|
||||||
# sibling's slug as the shared basename so Hugo pairs the set.
|
|
||||||
translations = post.get("translations", {})
|
|
||||||
es_id = translations.get("es", post["id"])
|
|
||||||
origin = by_id.get(es_id, post)
|
|
||||||
basename = origin["slug"]
|
|
||||||
|
|
||||||
# Anything that isn't the origin of its Polylang group is a translation.
|
|
||||||
origin_lang = LANG_MAP.get(origin.get("lang", "es"))
|
|
||||||
derived_from = origin_lang if origin_lang and origin_lang != lang else None
|
|
||||||
|
|
||||||
body_html = rewrite_images(post["content"]["rendered"], base_url)
|
|
||||||
md = (frontmatter(post, lang, categories, derived_from)
|
|
||||||
+ "\n\n" + to_markdown(body_html) + "\n")
|
|
||||||
|
|
||||||
out = POSTS_DIR / f"{basename}.{lang}.md"
|
|
||||||
out.write_text(md, encoding="utf-8")
|
|
||||||
written += 1
|
|
||||||
print(f" {out.relative_to(REPO_ROOT)}")
|
|
||||||
|
|
||||||
print(f"Wrote {written} files. Spot-check ~10 before committing (formatting fidelity).")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@ -1547,16 +1547,6 @@ a.group-pill:hover {
|
|||||||
color: var(--subtle);
|
color: var(--subtle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =========================================================
|
|
||||||
WordPress core image alignment
|
|
||||||
========================================================= */
|
|
||||||
|
|
||||||
.alignleft { float: left; margin: 0 1.5em 1em 0; }
|
|
||||||
.alignright { float: right; margin: 0 0 1em 1.5em; }
|
|
||||||
.aligncenter { display: block; margin: 0 auto 1em; }
|
|
||||||
.wp-caption { max-width: 100%; }
|
|
||||||
.wp-caption-text { font-size: 0.85rem; color: var(--muted); }
|
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
Clickable avatar wrapper (post cards + single post)
|
Clickable avatar wrapper (post cards + single post)
|
||||||
========================================================= */
|
========================================================= */
|
||||||
@ -4160,3 +4150,100 @@ a.notif-card__message:hover {
|
|||||||
letter-spacing: 0.02em;
|
letter-spacing: 0.02em;
|
||||||
vertical-align: middle;
|
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; }
|
||||||
|
}
|
||||||
|
|||||||
116
themes/vienalatina/assets/js/share.js
Normal file
116
themes/vienalatina/assets/js/share.js
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
})();
|
||||||
@ -41,6 +41,11 @@
|
|||||||
|
|
||||||
<h1 class="article-single__title">{{ .Title }}</h1>
|
<h1 class="article-single__title">{{ .Title }}</h1>
|
||||||
|
|
||||||
|
{{/* Twice on purpose: here for the reader who decides to send it to
|
||||||
|
somebody the moment they see what it is, and again after the text
|
||||||
|
for the one who decides having read it. */}}
|
||||||
|
{{ partial "share.html" . }}
|
||||||
|
|
||||||
{{/* An event leads with the three things somebody needs before they read
|
{{/* An event leads with the three things somebody needs before they read
|
||||||
a word: when, what time, and where. Everything else on the page is
|
a word: when, what time, and where. Everything else on the page is
|
||||||
the same article it would otherwise be. */}}
|
the same article it would otherwise be. */}}
|
||||||
@ -101,10 +106,18 @@
|
|||||||
</section>
|
</section>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ partial "share.html" . }}
|
||||||
|
|
||||||
<a class="back-link" href="{{ .Site.Home.Permalink }}">
|
<a class="back-link" href="{{ .Site.Home.Permalink }}">
|
||||||
← Volver al inicio
|
← Volver al inicio
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
{{/* Only on this template: the home page and the lists carry no share
|
||||||
|
row, so they should not carry its script either. Fingerprinted and
|
||||||
|
deferred like the others. */}}
|
||||||
|
{{ $share := resources.Get "js/share.js" | minify | fingerprint }}
|
||||||
|
<script src="{{ $share.RelPermalink }}" integrity="{{ $share.Data.Integrity }}" defer></script>
|
||||||
|
|
||||||
</article>
|
</article>
|
||||||
</main>
|
</main>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|||||||
23
themes/vienalatina/layouts/partials/og-image.html
Normal file
23
themes/vienalatina/layouts/partials/og-image.html
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{{/* The tags a share card needs to arrive with its picture.
|
||||||
|
|
||||||
|
One partial rather than the same five lines in three branches: the article,
|
||||||
|
the home page and a static page all share cards, and the set drifted once
|
||||||
|
already — the home page had no `twitter:image` for a while because it was
|
||||||
|
added to one branch and not the others.
|
||||||
|
|
||||||
|
Width and height are not decoration. Several clients draw the small card
|
||||||
|
instead of the large one when they would have to fetch the file to find
|
||||||
|
out how big it is, and WhatsApp in particular gives up on a slow or heavy
|
||||||
|
image rather than waiting for it. Both numbers come from the generated
|
||||||
|
card, so they cannot disagree with the file.
|
||||||
|
|
||||||
|
Takes: url, alt, width, height, type. */}}
|
||||||
|
{{ with .url }}
|
||||||
|
<meta property="og:image" content="{{ . }}">
|
||||||
|
<meta property="og:image:secure_url" content="{{ . }}">
|
||||||
|
{{ with $.alt }}<meta property="og:image:alt" content="{{ . }}">{{ end }}
|
||||||
|
{{ with $.width }}<meta property="og:image:width" content="{{ . }}">{{ end }}
|
||||||
|
{{ with $.height }}<meta property="og:image:height" content="{{ . }}">{{ end }}
|
||||||
|
{{ with $.type }}<meta property="og:image:type" content="{{ . }}">{{ end }}
|
||||||
|
<meta name="twitter:image" content="{{ . }}">
|
||||||
|
{{ end }}
|
||||||
@ -27,9 +27,46 @@
|
|||||||
one in config.yaml: most sites want their logo and the field exists for the
|
one in config.yaml: most sites want their logo and the field exists for the
|
||||||
ones that want something else. */}}
|
ones that want something else. */}}
|
||||||
{{ $fallback := or $chosen (or $brandLogo .Site.Params.defaultImage) }}
|
{{ $fallback := or $chosen (or $brandLogo .Site.Params.defaultImage) }}
|
||||||
{{ $image := "" }}
|
|
||||||
{{ with .Params.image }}{{ $image = . | absURL }}
|
{{/* The card is *generated*, not pointed at.
|
||||||
{{ else }}{{ with $fallback }}{{ $image = . | absURL }}{{ end }}{{ end }}
|
|
||||||
|
What used to go out was the original upload — 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 as a title and a
|
||||||
|
link with a blank where the picture should be. That is the whole reason
|
||||||
|
`static/uploads` is mounted into `assets/` in config.yaml: Hugo copies
|
||||||
|
static files and processes asset files, and only one of those can be
|
||||||
|
resized.
|
||||||
|
|
||||||
|
A post's own photograph is filled to 1200×630 — the size every client
|
||||||
|
draws its large card at — and comes out at 80–150 KB. The fallback is
|
||||||
|
fitted rather than filled, because a wordmark cropped to a landscape card
|
||||||
|
is a wordmark with its ends cut off.
|
||||||
|
|
||||||
|
An image the pipeline cannot find — a path typed by hand, a file added
|
||||||
|
after the build — falls back to exactly what happened before: the absolute
|
||||||
|
URL, no dimensions. Nothing is worse than it was. */}}
|
||||||
|
{{ $source := or .Params.image $fallback }}
|
||||||
|
{{ $image := "" }}{{ $cardW := "" }}{{ $cardH := "" }}{{ $cardType := "" }}
|
||||||
|
{{ with $source }}
|
||||||
|
{{ $image = . | absURL }}
|
||||||
|
{{ with resources.Get (strings.TrimPrefix "/" .) }}
|
||||||
|
{{ $card := "" }}
|
||||||
|
{{ if $.Params.image }}
|
||||||
|
{{ $card = .Fill "1200x630 Center q82 jpg" }}
|
||||||
|
{{ else }}
|
||||||
|
{{/* Fitted, and in its own format: the fallback is usually the logo, and a
|
||||||
|
logo cropped to a landscape card loses its ends — while converting a
|
||||||
|
transparent PNG to JPEG puts it on a black square, because JPEG has no
|
||||||
|
alpha to put it on anything else. */}}
|
||||||
|
{{ $card = .Fit "1200x630" }}
|
||||||
|
{{ end }}
|
||||||
|
{{ $image = $card.Permalink }}
|
||||||
|
{{ $cardW = $card.Width }}{{ $cardH = $card.Height }}{{ $cardType = $card.MediaType.Type }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
{{ $cardAlt := cond (ne .Params.image_alt nil) .Params.image_alt .Title }}
|
||||||
|
{{ $card := dict "url" $image "alt" $cardAlt "width" $cardW "height" $cardH "type" $cardType }}
|
||||||
|
|
||||||
<meta name="description" content="{{ $desc }}">
|
<meta name="description" content="{{ $desc }}">
|
||||||
|
|
||||||
@ -54,10 +91,7 @@
|
|||||||
{{ range .Translations }}
|
{{ range .Translations }}
|
||||||
{{ with index $localeMap .Language.Lang }}<meta property="og:locale:alternate" content="{{ . }}">{{ end }}
|
{{ with index $localeMap .Language.Lang }}<meta property="og:locale:alternate" content="{{ . }}">{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ with $image }}
|
{{ partial "og-image.html" $card }}
|
||||||
<meta property="og:image" content="{{ . }}">
|
|
||||||
<meta property="og:image:alt" content="{{ $.Params.image_alt | default $.Title }}">
|
|
||||||
{{ end }}
|
|
||||||
<meta property="article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" }}">
|
<meta property="article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" }}">
|
||||||
<meta property="article:modified_time" content="{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" }}">
|
<meta property="article:modified_time" content="{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" }}">
|
||||||
{{ with .Params.author }}<meta property="article:author" content="{{ . }}">{{ end }}
|
{{ with .Params.author }}<meta property="article:author" content="{{ . }}">{{ end }}
|
||||||
@ -65,7 +99,6 @@
|
|||||||
<meta name="twitter:card" content="{{ if $image }}summary_large_image{{ else }}summary{{ end }}">
|
<meta name="twitter:card" content="{{ if $image }}summary_large_image{{ else }}summary{{ end }}">
|
||||||
<meta name="twitter:title" content="{{ .Title }}">
|
<meta name="twitter:title" content="{{ .Title }}">
|
||||||
<meta name="twitter:description" content="{{ $desc }}">
|
<meta name="twitter:description" content="{{ $desc }}">
|
||||||
{{ with $image }}<meta name="twitter:image" content="{{ . }}">{{ end }}
|
|
||||||
|
|
||||||
{{ $schema := dict
|
{{ $schema := dict
|
||||||
"@context" "https://schema.org"
|
"@context" "https://schema.org"
|
||||||
@ -136,11 +169,7 @@
|
|||||||
{{/* The home page shared without a picture until there was one to use. Now
|
{{/* The home page shared without a picture until there was one to use. Now
|
||||||
that an admin can upload a logo, the front page of the site is the last
|
that an admin can upload a logo, the front page of the site is the last
|
||||||
place that should share as a bare link. */}}
|
place that should share as a bare link. */}}
|
||||||
{{ with $image }}
|
{{ partial "og-image.html" (merge $card (dict "alt" (partial "site-name.html" .))) }}
|
||||||
<meta property="og:image" content="{{ . }}">
|
|
||||||
<meta property="og:image:alt" content="{{ $.Site.Title }}">
|
|
||||||
<meta name="twitter:image" content="{{ . }}">
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{/* The organisation, as a search or answer engine reads it. Everything
|
{{/* The organisation, as a search or answer engine reads it. Everything
|
||||||
overridable lives in Gestión → Identidad; `areaServed` stays here because a
|
overridable lives in Gestión → Identidad; `areaServed` stays here because a
|
||||||
@ -215,15 +244,11 @@
|
|||||||
{{ range .Translations }}
|
{{ range .Translations }}
|
||||||
{{ with index $localeMap .Language.Lang }}<meta property="og:locale:alternate" content="{{ . }}">{{ end }}
|
{{ with index $localeMap .Language.Lang }}<meta property="og:locale:alternate" content="{{ . }}">{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ with $image }}
|
{{ partial "og-image.html" $card }}
|
||||||
<meta property="og:image" content="{{ . }}">
|
|
||||||
<meta property="og:image:alt" content="{{ $.Params.image_alt | default $.Title }}">
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
<meta name="twitter:card" content="{{ if $image }}summary_large_image{{ else }}summary{{ end }}">
|
<meta name="twitter:card" content="{{ if $image }}summary_large_image{{ else }}summary{{ end }}">
|
||||||
<meta name="twitter:title" content="{{ .Title }}">
|
<meta name="twitter:title" content="{{ .Title }}">
|
||||||
<meta name="twitter:description" content="{{ $desc }}">
|
<meta name="twitter:description" content="{{ $desc }}">
|
||||||
{{ with $image }}<meta name="twitter:image" content="{{ . }}">{{ end }}
|
|
||||||
|
|
||||||
{{ $schema := dict
|
{{ $schema := dict
|
||||||
"@context" "https://schema.org"
|
"@context" "https://schema.org"
|
||||||
|
|||||||
116
themes/vienalatina/layouts/partials/share.html
Normal file
116
themes/vienalatina/layouts/partials/share.html
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
{{/* The row of share buttons, drawn under the title and again after the text.
|
||||||
|
|
||||||
|
Four of these are ordinary links and work with scripting switched off:
|
||||||
|
WhatsApp, Facebook, Bluesky and Mastodon all accept a URL that opens their
|
||||||
|
own composer with the text already in it.
|
||||||
|
|
||||||
|
Signal and Instagram do not, and no amount of wanting changes it. Signal
|
||||||
|
has no web intent at all — it appears in the operating system's own share
|
||||||
|
sheet and nowhere else — and Instagram cannot be handed a link by anybody,
|
||||||
|
which is why every site that claims an Instagram share button is really
|
||||||
|
offering a copied link. So both call `navigator.share()`, which opens that
|
||||||
|
sheet with every installed app in it, and fall back to copying. They carry
|
||||||
|
`hidden` until share.js removes it: a button that does nothing at all is
|
||||||
|
worse than no button.
|
||||||
|
|
||||||
|
The icons are simplified marks in one visual language rather than the
|
||||||
|
official logo files. Reproducing those from memory gives something subtly
|
||||||
|
wrong, and subtly wrong looks worse than plainly simple; each carries its
|
||||||
|
name for a screen reader and in `title` for a cursor. Swapping in the real
|
||||||
|
SVGs later is one file and no other change. */}}
|
||||||
|
|
||||||
|
{{ $lang := .Site.Language.Lang }}
|
||||||
|
{{ $url := .Permalink }}
|
||||||
|
{{ $text := printf "%s — %s" .Title $url }}
|
||||||
|
{{/* Encoded once, and marked safe so it is not encoded again. Go's template
|
||||||
|
escaper treats an href as a URL and escapes it on the way out, so a value
|
||||||
|
that arrived already encoded came through as %253A and %2b — a link that
|
||||||
|
opens WhatsApp with the percent signs spelled out. */}}
|
||||||
|
{{ $encText := $text | urlquery }}
|
||||||
|
{{ $encUrl := $url | urlquery }}
|
||||||
|
|
||||||
|
{{/* Without scripting the Mastodon button needs an instance to aim at, and the
|
||||||
|
association's own is the only one this page knows. With scripting it asks
|
||||||
|
the reader for theirs instead and remembers the answer. */}}
|
||||||
|
{{ $masto := "" }}
|
||||||
|
{{ with site.Data.site }}{{ with .social }}{{ with .mastodon }}
|
||||||
|
{{ $masto = (urls.Parse .).Host }}
|
||||||
|
{{ end }}{{ end }}{{ end }}
|
||||||
|
|
||||||
|
<aside class="share" data-share
|
||||||
|
data-url="{{ $url }}"
|
||||||
|
data-title="{{ .Title }}"
|
||||||
|
data-text="{{ $text }}"
|
||||||
|
data-copied="{{ partial "t.html" (dict "key" "copied" "lang" $lang) }}"
|
||||||
|
data-ask="{{ partial "t.html" (dict "key" "askmasto" "lang" $lang) }}"
|
||||||
|
aria-label="{{ partial "t.html" (dict "key" "share" "lang" $lang) }}">
|
||||||
|
<span class="share__title">{{ partial "t.html" (dict "key" "share" "lang" $lang) }}</span>
|
||||||
|
|
||||||
|
<a class="share__btn share__btn--whatsapp" title="WhatsApp" rel="noopener"
|
||||||
|
target="_blank" href="{{ printf "https://wa.me/?text=%s" $encText | safeURL }}">
|
||||||
|
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
||||||
|
<path d="M12 2a9.8 9.8 0 0 0-8.4 15l-1.3 4.6 4.8-1.3A9.8 9.8 0 1 0 12 2Zm0 1.9a7.9 7.9 0 1 1-4.1 14.6l-.4-.2-2.6.7.7-2.5-.3-.4A7.9 7.9 0 0 1 12 3.9Z"/>
|
||||||
|
<path d="M9.4 7.6c-.2-.5-.4-.5-.6-.5h-.5c-.2 0-.5.1-.8.4-.3.3-1 1-1 2.4s1 2.8 1.2 3c.1.2 2 3.2 5 4.3 2.5.9 3 .7 3.5.7.6-.1 1.8-.7 2-1.5.3-.7.3-1.3.2-1.4l-.6-.3-1.9-.9c-.3-.1-.5-.2-.7.1l-.9 1.1c-.2.2-.3.2-.6.1a7.8 7.8 0 0 1-2.3-1.4 8.6 8.6 0 0 1-1.6-2c-.2-.3 0-.4.1-.6l.4-.5.3-.5v-.5l-.9-2.1Z"/>
|
||||||
|
</svg>
|
||||||
|
<span class="share__name">WhatsApp</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class="share__btn share__btn--facebook" title="Facebook" rel="noopener"
|
||||||
|
target="_blank" href="{{ printf "https://www.facebook.com/sharer/sharer.php?u=%s" $encUrl | safeURL }}">
|
||||||
|
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
||||||
|
<path d="M12 2a10 10 0 0 0-1.6 19.9v-7h-2.5V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9l2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.5 2.9h-2.3v7A10 10 0 0 0 12 2Z"/>
|
||||||
|
</svg>
|
||||||
|
<span class="share__name">Facebook</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class="share__btn share__btn--bluesky" title="Bluesky" rel="noopener"
|
||||||
|
target="_blank" href="{{ printf "https://bsky.app/intent/compose?text=%s" $encText | safeURL }}">
|
||||||
|
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
||||||
|
<path d="M12 10.8C10.9 8.7 7.9 4.7 5.2 3.3 2.6 2 1.6 3.4 1.6 5.3c0 1.9.8 7.9 1.3 8.9.9 1.7 2.6 2 4.1 1.8l-.6.1c-2.4.4-4.5 1.3-1.7 4.4 3 3.3 4.2-.7 4.8-2.7l.5-1.9.5 1.9c.6 2 1.8 6 4.8 2.7 2.8-3.1.7-4-1.7-4.4l-.6-.1c1.5.2 3.2-.1 4.1-1.8.5-1 1.3-7 1.3-8.9 0-1.9-1-3.3-3.6-2C16.1 4.7 13.1 8.7 12 10.8Z"/>
|
||||||
|
</svg>
|
||||||
|
<span class="share__name">Bluesky</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class="share__btn share__btn--mastodon" title="Mastodon" rel="noopener"
|
||||||
|
target="_blank" data-share-mastodon
|
||||||
|
{{ if $masto }}href="{{ printf "https://%s/share?text=%s" $masto $encText | safeURL }}"{{ else }}href="#" hidden{{ end }}>
|
||||||
|
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
||||||
|
<path d="M20.9 8.3c0-3.4-2.2-4.4-2.2-4.4C17.5 3.4 15.6 3.1 13.5 3h-.1c-2 0-4 .4-5.1.9 0 0-2.2 1-2.2 4.4v2.9c.1 3.4.6 6.8 3.7 7.6 1.5.4 2.7.5 3.7.4 1.8-.1 2.8-.6 2.8-.6l-.1-1.3s-1.2.4-2.6.3c-1.4 0-2.9-.1-3.1-1.9v-.5c3 .7 5.5.3 6.2.2 2-.2 3.7-1.5 3.9-2.6.3-1.8.3-4.5.3-4.5Zm-2.6 4.3h-1.6V8.7c0-.8-.3-1.2-1-1.2-.8 0-1.2.5-1.2 1.4v2H12.9v-2c0-.9-.4-1.4-1.2-1.4-.7 0-1 .4-1 1.2v3.9H9.1V8.6c0-.8.2-1.4.6-1.9.4-.4 1-.7 1.7-.7.8 0 1.4.3 1.8.9l.4.7.4-.7c.4-.6 1-.9 1.8-.9.7 0 1.3.3 1.7.7.4.5.6 1.1.6 1.9v4Z"/>
|
||||||
|
</svg>
|
||||||
|
<span class="share__name">Mastodon</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
{{/* The two with nowhere to send a link, and the universal fallback. All
|
||||||
|
three are hidden until share.js takes the attribute off. */}}
|
||||||
|
<button class="share__btn share__btn--signal" type="button" title="Signal"
|
||||||
|
data-share-native hidden>
|
||||||
|
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
||||||
|
<path d="M12 2.6a9.4 9.4 0 0 0-8.1 14.1l-1.2 3.9 4-1.1A9.4 9.4 0 1 0 12 2.6Zm0 1.9a7.5 7.5 0 1 1-3.9 13.9l-.4-.2-2.1.6.6-2-.2-.4A7.5 7.5 0 0 1 12 4.5Z"/>
|
||||||
|
</svg>
|
||||||
|
<span class="share__name">Signal</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button class="share__btn share__btn--instagram" type="button" title="Instagram"
|
||||||
|
data-share-native hidden>
|
||||||
|
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
||||||
|
<path d="M16.2 3H7.8A4.8 4.8 0 0 0 3 7.8v8.4A4.8 4.8 0 0 0 7.8 21h8.4a4.8 4.8 0 0 0 4.8-4.8V7.8A4.8 4.8 0 0 0 16.2 3Zm3 13.2a3 3 0 0 1-3 3H7.8a3 3 0 0 1-3-3V7.8a3 3 0 0 1 3-3h8.4a3 3 0 0 1 3 3v8.4Z"/>
|
||||||
|
<path d="M12 7.3a4.7 4.7 0 1 0 0 9.4 4.7 4.7 0 0 0 0-9.4Zm0 7.6a2.9 2.9 0 1 1 0-5.8 2.9 2.9 0 0 1 0 5.8Z"/>
|
||||||
|
<circle cx="17.1" cy="6.9" r="1.1"/>
|
||||||
|
</svg>
|
||||||
|
<span class="share__name">Instagram</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button class="share__btn share__btn--copy" type="button"
|
||||||
|
title="{{ partial "t.html" (dict "key" "copylink" "lang" $lang) }}"
|
||||||
|
data-share-copy hidden>
|
||||||
|
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
||||||
|
<path d="M10.6 13.4a3.6 3.6 0 0 0 5.1 0l2.9-2.9a3.6 3.6 0 0 0-5.1-5.1l-1.4 1.4 1.3 1.3 1.4-1.4a1.8 1.8 0 1 1 2.5 2.5l-2.9 2.9a1.8 1.8 0 0 1-2.5 0l-1.3 1.3Z"/>
|
||||||
|
<path d="M13.4 10.6a3.6 3.6 0 0 0-5.1 0l-2.9 2.9a3.6 3.6 0 0 0 5.1 5.1l1.4-1.4-1.3-1.3-1.4 1.4a1.8 1.8 0 1 1-2.5-2.5l2.9-2.9a1.8 1.8 0 0 1 2.5 0l1.3-1.3Z"/>
|
||||||
|
</svg>
|
||||||
|
<span class="share__name">{{ partial "t.html" (dict "key" "copylink" "lang" $lang) }}</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{{/* What the copy button says back. Polite rather than assertive: it
|
||||||
|
announces itself once rather than interrupting whatever is being read. */}}
|
||||||
|
<span class="share__said" role="status" aria-live="polite"></span>
|
||||||
|
</aside>
|
||||||
@ -19,6 +19,12 @@
|
|||||||
"noevents" (dict "es" "No hay nada en este mes." "de" "In diesem Monat ist nichts geplant." "pt-br" "Nada marcado neste mês.")
|
"noevents" (dict "es" "No hay nada en este mes." "de" "In diesem Monat ist nichts geplant." "pt-br" "Nada marcado neste mês.")
|
||||||
"allevents" (dict "es" "Todos los eventos" "de" "Alle Termine" "pt-br" "Todos os eventos")
|
"allevents" (dict "es" "Todos los eventos" "de" "Alle Termine" "pt-br" "Todos os eventos")
|
||||||
"ai" (dict "es" "Generado con IA" "de" "Mit KI erstellt" "pt-br" "Gerado com IA")
|
"ai" (dict "es" "Generado con IA" "de" "Mit KI erstellt" "pt-br" "Gerado com IA")
|
||||||
|
"share" (dict "es" "Compartir" "de" "Teilen" "pt-br" "Compartilhar")
|
||||||
|
"copylink" (dict "es" "Copiar enlace" "de" "Link kopieren" "pt-br" "Copiar link")
|
||||||
|
"copied" (dict "es" "Enlace copiado" "de" "Link kopiert" "pt-br" "Link copiado")
|
||||||
|
"askmasto" (dict "es" "¿En qué servidor de Mastodon tienes tu cuenta? Por ejemplo: mastodon.social"
|
||||||
|
"de" "Auf welchem Mastodon-Server hast du dein Konto? Zum Beispiel: mastodon.social"
|
||||||
|
"pt-br" "Em qual servidor do Mastodon está a sua conta? Por exemplo: mastodon.social")
|
||||||
"aifull" (dict "es" "Quien lo publicó marcó este texto como generado con inteligencia artificial."
|
"aifull" (dict "es" "Quien lo publicó marcó este texto como generado con inteligencia artificial."
|
||||||
"de" "Wer diesen Beitrag veröffentlicht hat, hat ihn als mit künstlicher Intelligenz erstellt gekennzeichnet."
|
"de" "Wer diesen Beitrag veröffentlicht hat, hat ihn als mit künstlicher Intelligenz erstellt gekennzeichnet."
|
||||||
"pt-br" "Quem publicou marcou este texto como gerado com inteligência artificial.")
|
"pt-br" "Quem publicou marcou este texto como gerado com inteligência artificial.")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user