From a551770c767a40a613b9972f8e05128cb93aa48c Mon Sep 17 00:00:00 2001 From: Phil Date: Sun, 1 Nov 2026 10:06:44 -0700 Subject: [PATCH] fix: Replies and photo posts read as the right post type (v2.6.5) Checked rendered pages with mf2py against W3C Post Type Discovery: - Note pages put u-in-reply-to inside a bare h-cite, making it the h-cite's property, so replies parsed as notes (or photo posts). The reply context is now the entry's u-in-reply-to h-cite. - Home page previews had no reply markup; they now show "In reply to" with u-in-reply-to. - Previews always emit e-content, so a text-free photo post can't get an implied name. - Text-free page titles follow PTD order (Repost, Like, Reply, Photo). tests/test_post_types.py runs PTD on parsed note pages and the home page. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 + .../v2.6.5/2026-11-01-micropub-media-fixes.md | 32 +++++++ templates/note.html | 9 +- templates/partials/note_preview.html | 7 +- tests/test_post_types.py | 84 +++++++++++++++++++ 5 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 tests/test_post_types.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 289532c..5fb3ff1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - A Micropub post that failed partway (for example, the same photo listed twice) answered "Failed to create post" but stayed published without its photos, so a client retrying would post it twice. Photos are now looked up before the post is made, and a post that fails after that is removed again - After such a failure, every request failed with "database is locked" for about 10 seconds: database connections now roll back unfinished writes when they're returned to the pool - The same photo listed twice in one post is shown once instead of failing the post +- Replies didn't read as replies to IndieWeb readers and webmention receivers: on note pages `u-in-reply-to` sat inside an unrelated `h-cite`, and the home page didn't mark replies at all, so [Post Type Discovery](https://www.w3.org/TR/post-type-discovery/) saw notes (or photo posts). The reply context is now the entry's `u-in-reply-to h-cite`, and home page entries show "↩ In reply to" +- Home page entries always have an `e-content`, so a photo post without text never gets an implied name (which readers would show as its caption) ### Changed diff --git a/docs/design/v2.6.5/2026-11-01-micropub-media-fixes.md b/docs/design/v2.6.5/2026-11-01-micropub-media-fixes.md index 2fe9cb9..0f771f8 100644 --- a/docs/design/v2.6.5/2026-11-01-micropub-media-fixes.md +++ b/docs/design/v2.6.5/2026-11-01-micropub-media-fixes.md @@ -37,8 +37,40 @@ spec rather than to StarPunk. - `syndication.py`: `compose_text` drops the leading blank line when there's no body. +## Post types (IndieWeb standards check) + +Post Type Discovery (W3C Note) has no separate "photo" type to store. A post +with a valid `photo` is a photo post, unless it's first a repost, like or +reply (step order: repost, like, reply, video, photo). Otherwise it's a note, +or an article when its `name` isn't a prefix of its content. h-entry treats +`u-photo` as the primary content, with `name` as a caption. mf2 implies a +`name` only when an entry has no other `p-*`/`e-*` properties and no nested +microformats. + +StarPunk already stores photo posts as notes with media and renders +`u-photo` outside `e-content`, which is what the standards ask for. Checking +the rendered pages with mf2py found: + +- **Replies weren't replies.** In `note.html`, `u-in-reply-to` was inside a + bare `h-cite`, so it was the h-cite's property, not the entry's. + `note_preview.html` had no reply markup at all. Fixed: the blockquote is + `u-in-reply-to h-cite` (with `u-url` inside), and previews show + "↩ In reply to" with `u-in-reply-to`. +- **Implied names were possible.** Previews left out `e-content` for posts + without text. They worked only because the author h-card blocked an + implied name. Previews now always emit `e-content`. +- Page title for text-free posts follows PTD order: Repost, Like, Reply, + Photo. + +`tests/test_post_types.py` parses note pages and the home page with mf2py and +runs PTD for notes, articles, photo posts (no text, caption, title), replies +(with and without a photo) and reposts. + ## Not changed (noted for later) +- Photos without alt text render `alt="Image"`, so parsers report alt text + nobody wrote (q=source correctly returns `""`). + - More than 4 photos are still cut to 4 without an error (ADR-057). - `video` and `audio` are ignored. This is allowed by the spec, and they aren't in `q=config` post-types. diff --git a/templates/note.html b/templates/note.html index fd4b537..5bfd222 100644 --- a/templates/note.html +++ b/templates/note.html @@ -2,7 +2,7 @@ {% from "partials/media.html" import display_media %} {% from "partials/reaction.html" import reaction %} -{% block title %}{% if note.content.strip().startswith('#') %}{{ note.title }}{% elif note.excerpt.strip() %}{{ note.excerpt|truncate(60) }}{% elif note.like_of %}Like{% elif note.repost_of %}Repost{% else %}Photo{% endif %} · {{ config.SITE_NAME }}{% endblock %} +{% block title %}{% if note.content.strip().startswith('#') %}{{ note.title }}{% elif note.excerpt.strip() %}{{ note.excerpt|truncate(60) }}{% elif note.repost_of %}Repost{% elif note.like_of %}Like{% elif note.in_reply_to %}Reply{% else %}Photo{% endif %} · {{ config.SITE_NAME }}{% endblock %} {% block content %}
@@ -18,13 +18,14 @@ {% if note.in_reply_to %}
In reply to: -
+ {# u-in-reply-to on the h-cite itself makes it the entry's property (Post Type Discovery) #} +
{% if reply_context and reply_context.fetch_status == 'fetched' %} {% if reply_context.content_snippet %}

{{ reply_context.content_snippet }}

{% endif %} - + {% if reply_context.author_name %}{{ reply_context.author_name }}{% endif %} {% if reply_context.site_name %} on {{ reply_context.site_name }}{% endif %} {% if not reply_context.author_name and not reply_context.site_name %}{{ note.in_reply_to }}{% endif %} @@ -32,7 +33,7 @@ {% else %} - {{ note.in_reply_to }} + {{ note.in_reply_to }} {% endif %}
diff --git a/templates/partials/note_preview.html b/templates/partials/note_preview.html index b8e11d5..ad54abe 100644 --- a/templates/partials/note_preview.html +++ b/templates/partials/note_preview.html @@ -9,6 +9,10 @@

{{ note.title }}

{% endif %} + {% if note.in_reply_to %} +

↩ In reply to {{ note.in_reply_to }}

+ {% endif %} + {{ reaction(note) }} {{ display_media(note.media) }} @@ -19,7 +23,8 @@

{{ note.excerpt }}

Read more →

- {% elif note.html %} + {% else %} + {# Always present, even empty: without it a text-free photo post gets an implied name (mf2) #}
{{ note.html|safe }}
diff --git a/tests/test_post_types.py b/tests/test_post_types.py new file mode 100644 index 0000000..56d6060 --- /dev/null +++ b/tests/test_post_types.py @@ -0,0 +1,84 @@ +""" +Rendered posts read as the right post type (v2.6.5). + +Parses note pages and the home page with mf2py, then runs W3C Post Type +Discovery (https://www.w3.org/TR/post-type-discovery/) on what a consumer +sees. A photo post is any post with a photo, unless it's first a repost, +like or reply. +""" + +import pytest +import mf2py + +import starpunk.reply_context as reply_context +from tests.test_micropub_v240 import SITE, app, client, h, jpeg # noqa: F401 +from tests.test_micropub_v265 import upload + + +def post_type(props): + """W3C Post Type Discovery, section 5 (no events or RSVPs here).""" + for prop, kind in [("repost-of", "repost"), ("like-of", "like"), ("in-reply-to", "reply"), + ("video", "video"), ("photo", "photo")]: + if props.get(prop): + return kind + + def first(prop): + for v in props.get(prop, []): + v = v.get("value", "") if isinstance(v, dict) else v + if v.strip(): + return " ".join(v.split()) + return "" + + content = first("content") or first("summary") + name = first("name") + if not content or not name or content.startswith(name): + return "note" + return "article" + + +def entries(items): + for item in items: + if "h-entry" in item.get("type", []): + yield item + yield from entries(item.get("children", [])) + + +def value(v): + """A u-* value, or the url of a nested microformat (h-cite).""" + return v.get("value") or v.get("properties", {}).get("url", [None])[0] if isinstance(v, dict) else v + + +CASES = { + "note": ({"content": ["Just a note"]}, "note"), + "article": ({"name": ["A Title"], "content": ["Body text here"]}, "article"), + "photo without text": ({"photo": ["PHOTO"]}, "photo"), + "photo with caption": ({"content": ["Sunset"], "photo": [{"value": "PHOTO", "alt": "Orange sky"}]}, "photo"), + "photo with title": ({"name": ["Trip"], "content": ["Day one"], "photo": ["PHOTO"]}, "photo"), + "reply": ({"content": ["Agreed"], "in-reply-to": ["https://other.example/post/1"]}, "reply"), + "reply with photo": ({"content": ["Mine"], "in-reply-to": ["https://other.example/post/2"], + "photo": ["PHOTO"]}, "reply"), + "repost": ({"repost-of": ["https://other.example/post/4"]}, "repost"), +} + + +@pytest.mark.parametrize("case", CASES) +def test_post_type(app, client, h, monkeypatch, case): + monkeypatch.setattr(reply_context, "fetch_reply_context", lambda *a, **k: None, raising=False) + props, want = CASES[case] + photo = upload(client, h) if "PHOTO" in str(props) else None + props = {k: [photo if v == "PHOTO" else ({**v, "value": photo} if isinstance(v, dict) else v) + for v in vs] for k, vs in props.items()} + response = client.post("/micropub", json={"type": ["h-entry"], "properties": props}, headers=h) + assert response.status_code == 201, response.get_json() + url = response.headers["Location"] + + (entry,) = entries(mf2py.parse(doc=client.get(url.replace(SITE, "")).data.decode(), url=url)["items"]) + home = mf2py.parse(doc=client.get("/").data.decode(), url=f"{SITE}/") + (listed,) = [e for e in entries(home["items"]) if e["properties"].get("url") == [url]] + + for e in (entry, listed): + assert post_type(e["properties"]) == want + if want == "reply": + assert value(e["properties"]["in-reply-to"][0]) == props["in-reply-to"][0] + if want == "photo" and "name" not in props: + assert "name" not in e["properties"], "no implied name to show as a caption"