feat: articles at /article/<slug> with slugs from their titles (v2.17.0, ADR-077)

Articles (notes with a title) move from /note/<slug> to /article/<slug>;
the other prefix 301-redirects. New articles take their slug from the
title (mp-slug still wins; notes keep timestamp slugs). A Micropub update
that adds or removes a title answers 201 with the new Location.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-12 12:27:31 -07:00
1 parent 66aecc2bcb
commit b7f8e1612c
26 files changed
+308 -60

No files matched your search

+85 -5
View File
@@ -38,7 +38,7 @@ class TestFeeds:
def test_rss_title_only_for_articles(self, app, client):
article, note = make_both(app)
items = {i.find("link").text: i for i in ET.fromstring(client.get("/feed.rss").data).iter("item")}
a, n = items[f"{SITE}/note/{article.slug}"], items[f"{SITE}/note/{note.slug}"]
a, n = items[f"{SITE}/article/{article.slug}"], items[f"{SITE}/note/{note.slug}"]
assert a.find("title").text == "An Article"
assert "An Article" not in a.find("description").text # not repeated in the body
assert n.find("title") is None
@@ -48,7 +48,7 @@ class TestFeeds:
article, note = make_both(app)
entries = {e.find("a:id", ATOM).text: e
for e in ET.fromstring(client.get("/feed.atom").data).findall("a:entry", ATOM)}
a, n = entries[f"{SITE}/note/{article.slug}"], entries[f"{SITE}/note/{note.slug}"]
a, n = entries[f"{SITE}/article/{article.slug}"], entries[f"{SITE}/note/{note.slug}"]
assert a.find("a:title", ATOM).text == "An Article"
assert a.find("a:summary", ATOM).text == "The gist."
assert "An Article" not in a.find("a:content", ATOM).text
@@ -58,7 +58,7 @@ class TestFeeds:
def test_json_feed(self, app, client):
article, note = make_both(app)
items = {i["url"]: i for i in json.loads(client.get("/feed.json").data)["items"]}
a, n = items[f"{SITE}/note/{article.slug}"], items[f"{SITE}/note/{note.slug}"]
a, n = items[f"{SITE}/article/{article.slug}"], items[f"{SITE}/note/{note.slug}"]
assert (a["title"], a["summary"]) == ("An Article", "The gist.")
assert "An Article" not in a["content_html"]
assert "title" not in n and "summary" not in n
@@ -68,8 +68,8 @@ class TestFeeds:
class TestPages:
def test_article_page(self, app, client):
article, _ = make_both(app)
(entry,) = [i for i in mf2py.parse(doc=client.get(f"/note/{article.slug}").data.decode(),
url=f"{SITE}/note/{article.slug}")["items"]
(entry,) = [i for i in mf2py.parse(doc=client.get(f"/article/{article.slug}").data.decode(),
url=f"{SITE}/article/{article.slug}")["items"]
if "h-entry" in i["type"]]
props = entry["properties"]
assert props["name"] == ["An Article"]
@@ -193,3 +193,83 @@ class TestInlineImages:
"replace": {"content": ["![A](https://cdn.example/a.jpg)"]}}, headers=h)
with app.app_context():
assert f"]({SITE}/media/" in get_note(slug=url.rsplit("/", 1)[1]).content
class TestArticleUrls:
"""Articles live at /article/<title-slug>, notes at /note/<slug> (v2.17.0)"""
def test_micropub_article_gets_article_url_from_title(self, app, client, h):
url = micropub(client, h, name=["Why I Left Twitter!"], content=["Long story."])
assert url == f"{SITE}/article/why-i-left-twitter"
assert source(client, h, url)["properties"]["url"] == [url]
assert client.get("/article/why-i-left-twitter").status_code == 200
def test_note_keeps_note_url_and_timestamp_slug(self, app, client, h):
url = micropub(client, h, content=["Just a note"])
assert url.startswith(f"{SITE}/note/") and url.rsplit("/", 1)[1][:8].isdigit()
def test_wrong_prefix_redirects(self, app, client, h):
article = micropub(client, h, name=["Moved"], content=["Body"])
note = micropub(client, h, content=["Plain"])
slug, note_slug = article.rsplit("/", 1)[1], note.rsplit("/", 1)[1]
response = client.get(f"/note/{slug}")
assert (response.status_code, response.location) == (301, f"/article/{slug}")
response = client.get(f"/article/{note_slug}")
assert (response.status_code, response.location) == (301, f"/note/{note_slug}")
assert client.get("/article/no-such-post").status_code == 404
def test_micropub_accepts_either_url(self, app, client, h):
url = micropub(client, h, name=["Either"], content=["Body"])
old_style = url.replace("/article/", "/note/")
response = client.post("/micropub", json={"action": "update", "url": old_style,
"replace": {"summary": ["S"]}}, headers=h)
assert response.status_code == 204
assert source(client, h, url)["properties"]["summary"] == ["S"]
def test_title_slugs(self, app):
with app.test_request_context():
def slug(title, **kw):
return create_note(content="Body", title=title, published=True, **kw).slug
assert slug("Café Culture") == "cafe-culture"
assert slug("Café Culture") == "cafe-culture-2"
assert slug("Search") == "search-article" # reserved
assert slug("Mine", custom_slug="chosen") == "chosen" # mp-slug wins
assert slug("🎉🎉").isdigit() # nothing usable: timestamp
long = slug("word " * 40)
assert len(long) <= 80 and long.endswith("word") and "--" not in long
def test_update_that_adds_or_removes_title_returns_new_url(self, app, client, h):
note = micropub(client, h, content=["Starts as a note"])
slug = note.rsplit("/", 1)[1]
response = client.post("/micropub", json={"action": "update", "url": note,
"replace": {"name": ["Now an Article"]}}, headers=h)
assert (response.status_code, response.headers["Location"]) == (201, f"{SITE}/article/{slug}")
response = client.post("/micropub", json={"action": "update", "url": f"{SITE}/article/{slug}",
"replace": {"content": ["Edited"]}}, headers=h)
assert response.status_code == 204 # URL unchanged
response = client.post("/micropub", json={"action": "update", "url": f"{SITE}/article/{slug}",
"delete": ["name"]}, headers=h)
assert (response.status_code, response.headers["Location"]) == (201, f"{SITE}/note/{slug}")
def test_deleted_article_is_gone(self, app, client, h):
url = micropub(client, h, name=["Short-lived"], content=["Body"])
assert client.post("/micropub", data={"action": "delete", "url": url}, headers=h).status_code == 204
assert client.get("/article/short-lived").status_code == 410
def test_webmention_target_and_links(self, app, client):
article, note = make_both(app)
from starpunk.routes.webmention import resolve_target_note
with app.test_request_context():
assert resolve_target_note(f"{SITE}/article/{article.slug}") == article.id
assert resolve_target_note(f"{SITE}/note/{article.slug}") == article.id
assert resolve_target_note(f"{SITE}/article/{article.slug}/x") is None
html = client.get("/").data.decode()
assert f'href="{SITE}/article/{article.slug}"' in html
assert f'href="{SITE}/note/{note.slug}"' in html
assert f"/note/{article.slug}" not in html
def test_search_links_to_article(self, app, client):
article, _ = make_both(app)
results = client.get("/api/search?q=body").get_json()["results"]
assert [r["url"] for r in results if r["slug"] == article.slug] == [f"/article/{article.slug}"]