The last of WordPress
`/wp-cron.php` was reaching the Flask app. The matcher for old WordPress paths listed four of them by name and missed that one, so it fell through to the single-segment profile route — `/wp-cron.php` looks exactly like a member's name — and was answered with a 400 by the CSRF hook. The old install has been POSTing it every few minutes, which means the members area was being woken up by the site it replaced. The matcher is now `/wp-*`, after the uploads rule and never before it, so the migrated pictures still map. `/categoria/…` was redirecting to `/categories/…`, which stopped existing when the taxonomies were removed: one dead address forwarding to another. It goes home now. vielac.at is the old site's own domain rather than a spare name, which is worth saying in the file that redirects it: it is the address in every link shared before the cutover and every search result not yet recrawled. An old WordPress path arriving there lands on vienalatina.com and is caught by the 301s further down — one set of rules rather than two. Deleted with it: `scripts/wp-to-hugo.py`, whose own docstring called it disposable and whose migration happened; its section in the README, which now says what remains of that site instead; and the WordPress core alignment CSS, which no content uses and nothing in the editor can produce. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
This commit is contained in:
parent
3e610ac5d2
commit
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/...`).
|
|
||||||
|
|||||||
@ -41,8 +41,10 @@ local$ dig +short git.vienalatina.com
|
|||||||
|
|
||||||
### 1.1 A second domain that leads here
|
### 1.1 A second domain that leads here
|
||||||
|
|
||||||
`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, and
|
||||||
to the same path on vienalatina.com. Two A records in that domain's **zone
|
it redirects: everything that arrives goes to the same path on vienalatina.com,
|
||||||
|
where the 301s for old WordPress paths catch it. Pointing it here is also what
|
||||||
|
takes the last traffic off the old box. Two A records in that domain's **zone
|
||||||
editor**, both at the server:
|
editor**, both at the server:
|
||||||
|
|
||||||
| Name | Type | Value | TTL |
|
| Name | Type | Value | TTL |
|
||||||
|
|||||||
@ -21,14 +21,18 @@ 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 old site's own domain. 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 that has not been recrawled, and in the
|
||||||
|
# bookmarks of everybody who read it.
|
||||||
#
|
#
|
||||||
# Both spellings in one block, and 301 rather than 302: a permanent redirect is
|
# Both spellings in one block, and 301 rather than 302: a permanent redirect is
|
||||||
# what makes a search engine fold the two names into one site instead of
|
# what makes a search engine fold the two names into one site instead of
|
||||||
# indexing them as duplicates of each other, and what makes a browser stop
|
# indexing them as duplicates of each other, and what makes a browser stop
|
||||||
# asking after the first visit. `{uri}` carries the path, so a link somebody
|
# asking after the first visit. `{uri}` carries the path, so a link somebody
|
||||||
# shared to vielac.at/page/agenda/ lands on the agenda rather than on the home
|
# shared to vielac.at/page/agenda/ lands on the agenda rather than on the home
|
||||||
# page.
|
# page — and an old WordPress path arrives at vienalatina.com and is caught by
|
||||||
|
# the 301s further down, which is one set of rules rather than two.
|
||||||
#
|
#
|
||||||
# Caddy asks Let's Encrypt for this certificate the first time the name
|
# Caddy asks Let's Encrypt for this certificate the first time the name
|
||||||
# resolves to this server, so the A records go in before this file is reloaded.
|
# resolves to this server, so the A records go in before this file is reloaded.
|
||||||
@ -98,9 +102,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 +116,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)
|
||||||
========================================================= */
|
========================================================= */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user