feat: article titles and summaries stored apart from the text (v2.16.0, ADR-076)

Articles as the IndieWeb defines them: a name separate from the content.

- Migration 023 adds notes.title and notes.summary. A one-time Python data
  step (migrations.DATA_MIGRATIONS) moves each note's '# Heading' first line
  into title, rewrites the file and hash, empties FTS for a rebuild, and puts
  files back if the migration fails. Trashed notes included.
- Micropub: name -> title, summary stored when sent with content, summary
  updatable, q=source returns both. MCP tools take a summary.
- Feeds: titles only for articles (RSS/JSON none, Atom empty); Atom and
  JSON Feed summaries; the title is no longer repeated in the content.
- Pages: p-name/p-summary on the article page. Homepage and tag pages show
  articles as title, summary and "Read more" without images (hidden u-photo
  keeps the post type for parsers).
- Crossposts: articles go out as title, summary, link and hashtags, no
  images; the Bluesky card is the article. Notes unchanged.
- Editor: Title and Summary fields; an article may have no body.
- Fix: a line starting with a hashtag ('#indieweb ...') was rendered as a
  heading and crossposted without its '#' (HashtagLineExtension).
- Fix: excerpts showed raw Markdown; they are plain text now.

Back up the database and the data folder before deploying: the migration
rewrites note files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-11 17:05:38 -07:00
1 parent 9a0d82bab2
commit 978c13358b
44 files changed
+943 -356

No files matched your search

+49 -26
View File
@@ -7,7 +7,8 @@ interface for creating posts via external clients.
Functions:
normalize_properties: Convert form/JSON data to Micropub properties format
extract_content: Get content from Micropub properties
extract_title: Get the explicit title (name) from Micropub properties
extract_title: Get the title (name) from Micropub properties
extract_summary: Get the author's summary from Micropub properties
extract_tags: Get category tags from Micropub properties
handle_create: Process Micropub create action
handle_update: Process Micropub update action (v2.4.0)
@@ -235,10 +236,7 @@ def _has_text(content) -> bool:
def extract_title(properties: dict) -> Optional[str]:
"""
Extract the explicit title (Micropub 'name' property)
StarPunk has no title field: a note's title is a '# Heading' first line
(see Note.title), so the caller stores the name as that heading.
Extract the title (Micropub 'name' property), stored in notes.title (ADR-076)
Args:
properties: Normalized Micropub properties dict
@@ -252,14 +250,22 @@ def extract_title(properties: dict) -> Optional[str]:
return " ".join(name.split()) or None
def add_title_heading(content: str, title: Optional[str]) -> str:
"""Prefix content with '# title' unless it already starts with that heading"""
if not title:
return content
first_line = content.lstrip().split("\n", 1)[0]
if first_line.startswith("#") and first_line.lstrip("#").strip() == title:
return content
return f"# {title}\n\n{content}"
def extract_summary(properties: dict) -> Optional[str]:
"""The author's summary (Micropub 'summary' property, v2.16.0), as plain text"""
summary = _first(properties.get("summary"))
if isinstance(summary, dict):
summary = summary.get("text") or summary.get("value") or ""
if not isinstance(summary, str):
return None
return summary.strip() or None
def drop_title_heading(content: str, title: Optional[str]) -> str:
"""Content without a '# heading' first line that only repeats the title"""
heading, rest = split_title(content)
if title and heading == title:
return rest
return content
def extract_tags(properties: dict) -> list[str]:
@@ -308,7 +314,7 @@ MAX_PHOTOS = 4 # ADR-057
MAX_REMOTE_PHOTO_BYTES = 20 * 1024 * 1024
# Properties we can store, and so can be updated (v2.4.0)
UPDATABLE = {"content", "name", "category", "in-reply-to", "post-status", "photo"}
UPDATABLE = {"content", "name", "summary", "category", "in-reply-to", "post-status", "photo"}
def _first(value):
@@ -596,6 +602,10 @@ def handle_create(data: dict, token_info: dict, files=None):
if has_content or not (like_of or repost_of or bookmark_of or photos or title)
else ""
)
content = drop_title_heading(content, title)
# A summary with content is the author's summary; alone it is the
# content (Post Type Discovery), as extract_content does (v2.16.0)
summary = extract_summary(properties) if _has_text(properties.get("content")) else None
tags = extract_tags(properties)
published_date = extract_published_date(properties)
published = extract_post_status(properties) and not extract_visibility_draft(properties)
@@ -615,7 +625,9 @@ def handle_create(data: dict, token_info: dict, files=None):
note = None
try:
note = create_note(
content=add_title_heading(content, title),
content=content,
title=title,
summary=summary,
published=published,
created_at=published_date,
custom_slug=custom_slug,
@@ -686,7 +698,7 @@ def handle_update(data: dict, token_info: dict):
from starpunk.tags import get_note_tags
title, body = split_title(note.content)
title, summary, body = note.title, note.summary, note.content
tags = [t["display_name"] for t in get_note_tags(note.id, entered_order=True)]
photos = _note_photos(note)
changes = {}
@@ -696,6 +708,8 @@ def handle_update(data: dict, token_info: dict):
for prop in delete:
if prop == "name":
title = None
elif prop == "summary":
summary = None
elif prop == "content":
body = ""
elif prop == "category":
@@ -723,6 +737,8 @@ def handle_update(data: dict, token_info: dict):
changes["content_format"] = content_format(replace) if body else None
if "name" in replace:
title = extract_title(replace)
if "summary" in replace:
summary = extract_summary(replace)
if "category" in replace:
tags = extract_tags(replace)
if "photo" in replace:
@@ -738,17 +754,22 @@ def handle_update(data: dict, token_info: dict):
if "photo" in add:
photos += extract_photos(add)
# Text may go only if photos stay (or it's a like, repost or bookmark) (v2.6.5)
if not (body or "").strip() and not (photos or note.reacts_to):
raise MicropubValidationError("A post needs text or a photo")
# Text may go only if photos stay, it has a title, or it's a like, repost
# or bookmark (v2.6.5)
if not (body or "").strip() and not (photos or title or note.reacts_to):
raise MicropubValidationError("A post needs text, a title or a photo")
# Photos must all resolve before anything changes (v2.9.0)
if "photo" in touched:
media_ids, captions = _resolve_photos(photos)
new_content = add_title_heading(body, title)
if new_content != note.content:
changes["content"] = new_content
if title != note.title:
changes["title"] = title
if summary != note.summary:
changes["summary"] = summary
body = drop_title_heading(body, title)
if body != note.content:
changes["content"] = body
elif "content_format" in changes and changes["content_format"] == note.content_format:
del changes["content_format"]
if {"category"} & touched:
@@ -800,11 +821,11 @@ def note_to_mf2(note, wanted: Optional[list] = None) -> dict:
"""
A note as Microformats2 JSON, the inverse of create
A '# Heading' first line is the title, returned as name.
The title is returned as name and the author's summary as summary.
"""
from starpunk.syndication import get_note_syndications
title, content = split_title(note.content)
content = note.content
props = {
# HTML-authored content comes back as HTML (3.7.2, v2.9.0)
"content": [{"html": content} if note.content_format == "html" else content],
@@ -812,8 +833,10 @@ def note_to_mf2(note, wanted: Optional[list] = None) -> dict:
"url": [absolute_url_for("public.note", slug=note.slug)],
"post-status": ["published" if note.published else "draft"],
}
if title:
props["name"] = [title]
if note.title:
props["name"] = [note.title]
if note.summary:
props["summary"] = [note.summary]
from starpunk.tags import get_note_tags
tags = get_note_tags(note.id, entered_order=True)