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

+41 -21
View File
@@ -149,6 +149,8 @@ def create_note(
has_media: bool = False,
bookmark_of: Optional[str] = None,
content_format: Optional[str] = None,
title: Optional[str] = None,
summary: Optional[str] = None,
) -> Note:
"""
Create a new note
@@ -164,6 +166,8 @@ def create_note(
custom_slug: Optional custom slug (from Micropub mp-slug property)
tags: Optional list of tag display names (v1.3.0)
in_reply_to: Optional URL being replied to (v1.6.0)
title: Optional title; a titled note is an article (v2.16.0, ADR-076)
summary: Optional author-written summary (v2.16.0)
Returns:
Note object with all metadata and content loaded
@@ -176,7 +180,7 @@ def create_note(
Examples:
>>> # Create unpublished draft
>>> note = create_note("# My First Note\\n\\nContent here.", published=False)
>>> note = create_note("Content here.", title="My First Note", published=False)
>>> print(note.slug)
'my-first-note'
@@ -219,7 +223,9 @@ def create_note(
"like_of", like_of, "A note can only be one of a like, repost or bookmark"
)
content = content or ""
if not content.strip() and not (like_of or repost_of or bookmark_of or has_media):
title = (title or "").strip() or None
summary = (summary or "").strip() or None
if not content.strip() and not (like_of or repost_of or bookmark_of or has_media or title):
raise InvalidNoteDataError(
"content", content, "Content cannot be empty or whitespace-only"
)
@@ -281,11 +287,12 @@ def create_note(
db.execute(
"""
INSERT INTO notes (slug, file_path, published, created_at, updated_at, content_hash,
in_reply_to, like_of, repost_of, bookmark_of, content_format)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
in_reply_to, like_of, repost_of, bookmark_of, content_format,
title, summary)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(slug, file_path_rel, published, created_at, updated_at, content_hash,
in_reply_to, like_of, repost_of, bookmark_of, content_format),
in_reply_to, like_of, repost_of, bookmark_of, content_format, title, summary),
)
db.commit()
except Exception as e:
@@ -327,7 +334,7 @@ def create_note(
from starpunk.search import update_fts_index, has_fts_table
db_path = Path(current_app.config["DATABASE_PATH"])
if has_fts_table(db_path):
update_fts_index(db, note_id, slug, content)
update_fts_index(db, note_id, slug, content, title)
db.commit()
except Exception as e:
# FTS update failure should not prevent note creation
@@ -641,11 +648,14 @@ def update_note(
in_reply_to: Optional[str] = None,
has_media: bool = False,
content_format=UNCHANGED,
title=UNCHANGED,
summary=UNCHANGED,
) -> Note:
"""
Update a note's content and/or published status
content_format (v2.9.0): 'html' or None (Markdown); left alone unless given
title, summary (v2.16.0): new value, None or "" to remove; left alone unless given
Updates note content and/or metadata, maintaining atomic synchronization
between file and database. At least one of content or published must
@@ -713,8 +723,15 @@ def update_note(
if slug is not None and id is not None:
raise ValueError("Cannot provide both slug and id")
if content is None and published is None and tags is None and in_reply_to is None:
raise ValueError("Must provide at least one of content, published, tags, or in_reply_to to update")
if (content is None and published is None and tags is None and in_reply_to is None
and title is UNCHANGED and summary is UNCHANGED):
raise ValueError(
"Must provide at least one of content, published, tags, in_reply_to, title or summary to update"
)
if title is not UNCHANGED:
title = (title or "").strip() or None
if summary is not UNCHANGED:
summary = (summary or "").strip() or None
# Validate content if provided (checked against the note below for
# likes/reposts, whose comment may be empty)
@@ -729,7 +746,8 @@ def update_note(
raise NoteNotFoundError(identifier)
old_tag_names = _tag_names(existing_note.id) # for WebSub tag topics (v2.10.0)
if empty_content and not (existing_note.reacts_to or has_media):
new_title = existing_note.title if title is UNCHANGED else title
if empty_content and not (existing_note.reacts_to or has_media or new_title):
raise InvalidNoteDataError(
"content", content, "Content cannot be empty or whitespace-only"
)
@@ -797,6 +815,14 @@ def update_note(
update_fields.append("content_format = ?")
params.append(content_format)
if title is not UNCHANGED:
update_fields.append("title = ?")
params.append(title)
if summary is not UNCHANGED:
update_fields.append("summary = ?")
params.append(summary)
# Add WHERE clause parameter
if slug is not None:
where_clause = "slug = ?"
@@ -832,13 +858,14 @@ def update_note(
# Tag update failure should not prevent note update
current_app.logger.warning(f"Failed to update tags for note {existing_note.slug}: {e}")
# 7. UPDATE FTS INDEX (if available and content changed)
if content is not None:
# 7. UPDATE FTS INDEX (if available and content or title changed)
if content is not None or title is not UNCHANGED:
try:
from starpunk.search import update_fts_index, has_fts_table
db_path = Path(current_app.config["DATABASE_PATH"])
if has_fts_table(db_path):
update_fts_index(db, existing_note.id, existing_note.slug, content)
update_fts_index(db, existing_note.id, existing_note.slug,
existing_note.content if content is None else content, new_title)
db.commit()
except Exception as e:
# FTS update failure should not prevent note update
@@ -1129,7 +1156,7 @@ def undelete_note(slug: str) -> Note:
NoteNotFoundError: If there is no soft-deleted note with this slug
"""
import shutil
from starpunk.utils import TRASH_DIR_NAME
from starpunk.utils import find_trashed_file
db = get_db(current_app)
row = db.execute(
@@ -1142,14 +1169,7 @@ def undelete_note(slug: str) -> Note:
data_dir = Path(current_app.config["DATA_PATH"])
note_path = data_dir / row["file_path"]
if not note_path.exists():
# delete_note_file put it in .trash/<year>/<month>/<name>
parts = Path(row["file_path"]).parts
candidates = []
if "notes" in parts and len(parts) > parts.index("notes") + 2:
i = parts.index("notes")
candidates.append(data_dir / TRASH_DIR_NAME / parts[i + 1] / parts[i + 2] / note_path.name)
candidates += sorted((data_dir / TRASH_DIR_NAME).glob(f"*/*/{note_path.name}"))
source = next((c for c in candidates if c.exists()), None)
source = find_trashed_file(data_dir, row["file_path"])
if source is None:
raise NoteSyncError("undelete", f"Trashed file not found for {slug}", "Cannot restore note file")
note_path.parent.mkdir(parents=True, exist_ok=True)