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

+20 -20
View File
@@ -98,29 +98,32 @@ def has_fts_table(db_path: Path) -> bool:
return False
def update_fts_index(conn: sqlite3.Connection, note_id: int, slug: str, content: str):
def _first_line(content: str) -> str:
"""A note's first line without heading marks (result label for untitled notes).
A hashtag ('#indieweb ...') is kept."""
line = content.split('\n', 1)[0].strip()
return re.sub(r'^#{1,6}\s+', '', line)
def update_fts_index(conn: sqlite3.Connection, note_id: int, slug: str, content: str,
title: Optional[str] = None):
"""
Update FTS index for a note (insert or replace)
Extracts title from first line of content and updates the FTS index.
Uses REPLACE to handle both new notes and updates.
Indexes the note's title (articles, v2.16.0) or, for untitled notes, its
first line. Uses REPLACE to handle both new notes and updates.
Args:
conn: SQLite database connection
note_id: Note ID (used as FTS rowid)
slug: Note slug
content: Full markdown content
content: Markdown content
title: The note's title, if it has one
Raises:
sqlite3.Error: If FTS update fails
"""
# Extract title from first line
lines = content.split('\n', 1)
title = lines[0].strip() if lines else ''
# Remove markdown heading syntax (# ## ###)
if title.startswith('#'):
title = title.lstrip('#').strip()
title = title or _first_line(content)
# Limit title length
if len(title) > 100:
@@ -170,7 +173,7 @@ def rebuild_fts_index(db_path: Path, data_dir: Path):
# Get all non-deleted notes
cursor = conn.execute(
"SELECT id, slug, file_path FROM notes WHERE deleted_at IS NULL"
"SELECT id, slug, file_path, title FROM notes WHERE deleted_at IS NULL"
)
indexed_count = 0
@@ -188,7 +191,7 @@ def rebuild_fts_index(db_path: Path, data_dir: Path):
content = note_path.read_text(encoding='utf-8')
# Update FTS index
update_fts_index(conn, row['id'], row['slug'], content)
update_fts_index(conn, row['id'], row['slug'], content, row['title'])
indexed_count += 1
except Exception as e:
@@ -408,6 +411,7 @@ def search_notes_fallback(
id,
slug,
file_path,
title,
published,
created_at
FROM notes
@@ -446,8 +450,8 @@ def search_notes_fallback(
file_path = data_dir / row['file_path']
content = read_note_file(file_path)
# Check if query matches content (case-insensitive)
content_lower = content.lower()
# Check if query matches title or content (case-insensitive)
content_lower = f"{row['title'] or ''}\n{content}".lower()
query_lower = query.lower()
matches = query_lower in content_lower
@@ -456,11 +460,7 @@ def search_notes_fallback(
matches = any(term.lower() in content_lower for term in terms)
if matches:
# Extract title from first line
lines = content.split('\n', 1)
title = lines[0].strip() if lines else row['slug']
if title.startswith('#'):
title = title.lstrip('#').strip()
title = row['title'] or _first_line(content) or row['slug']
results.append({
'id': row['id'],