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

+67 -1
View File
@@ -344,7 +344,65 @@ def apply_migration(conn, migration_name, migration_path, logger=None):
raise MigrationError(error_msg)
def run_migrations(db_path, logger=None):
def _move_note_titles(conn, data_dir, logger):
"""
Migration 023 data step: move each note's '# Heading' title into notes.title
Runs once, inside the migration transaction. Rewrites the note files without
the heading and returns [(path, original text)] so a failed migration can
put them back (see _restore_files).
"""
from starpunk.models import split_title
from starpunk.utils import calculate_content_hash, find_trashed_file, write_note_file
data_dir = Path(data_dir)
written = []
try:
rows = conn.execute(
"SELECT id, slug, file_path FROM notes WHERE title IS NULL"
).fetchall()
for note_id, slug, file_path in rows:
path = data_dir / file_path
if not path.exists():
path = find_trashed_file(data_dir, file_path)
if path is None:
logger.warning(f"Migration 023: no file for note {slug}, title not moved")
continue
text = path.read_text(encoding="utf-8")
title, body = split_title(text)
if title is None:
continue
conn.execute(
"UPDATE notes SET title = ?, content_hash = ? WHERE id = ?",
(title, calculate_content_hash(body), note_id),
)
write_note_file(path, body)
written.append((path, text))
if written and table_exists(conn, "notes_fts"):
# Emptied so startup rebuilds it with the titles (starpunk/__init__.py)
conn.execute("DELETE FROM notes_fts")
logger.info(f"Migration 023: moved {len(written)} titles out of note files")
return written
except Exception:
_restore_files(written, logger)
raise
def _restore_files(written, logger):
"""Put back note files changed by a data step whose migration failed"""
for path, text in written:
try:
path.write_text(text, encoding="utf-8")
except OSError as e:
logger.critical(f"Could not restore {path} after failed migration: {e}")
# Python steps run right after a migration's SQL, in the same transaction.
# Each returns [(path, original text)] for files it changed.
DATA_MIGRATIONS = {"023_note_titles.sql": _move_note_titles}
def run_migrations(db_path, logger=None, data_dir=None):
"""
Run all pending database migrations with concurrency protection
@@ -374,6 +432,8 @@ def run_migrations(db_path, logger=None):
Args:
db_path: Path to SQLite database file
logger: Optional logger for output
data_dir: Data directory, for migrations that also change note files
(DATA_MIGRATIONS); skipped when None
Raises:
MigrationError: If any migration fails to apply or lock cannot be acquired
@@ -407,6 +467,7 @@ def run_migrations(db_path, logger=None):
# BEGIN IMMEDIATE acquires RESERVED lock, preventing other writes
# but allowing reads. Escalates to EXCLUSIVE during actual writes.
conn.execute("BEGIN IMMEDIATE")
written = [] # note files changed by DATA_MIGRATIONS, restored on failure
try:
# Ensure migrations tracking table exists
@@ -510,6 +571,9 @@ def run_migrations(db_path, logger=None):
# Execute migration inside the locked transaction
execute_in_transaction(conn, migration_sql)
data_step = DATA_MIGRATIONS.get(migration_name)
if data_step and data_dir is not None:
written += data_step(conn, data_dir, logger)
# Record migration as applied
conn.execute(
@@ -547,6 +611,7 @@ def run_migrations(db_path, logger=None):
except MigrationError:
# Migration error - rollback and re-raise
_restore_files(written, logger)
try:
conn.rollback()
except Exception as rollback_error:
@@ -556,6 +621,7 @@ def run_migrations(db_path, logger=None):
except Exception as e:
# Unexpected error during migration - rollback and wrap
_restore_files(written, logger)
try:
conn.rollback()
except Exception as rollback_error: