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:
1 parent
9a0d82bab2
commit
978c13358b
44 files changed
+943
-356
No files matched your search
+34
-48
@@ -11,6 +11,7 @@ Organized by model:
|
||||
import pytest
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
from dataclasses import replace
|
||||
from starpunk.models import Note, Session, Token, AuthState, split_title
|
||||
from starpunk.utils import calculate_content_hash
|
||||
|
||||
@@ -139,13 +140,12 @@ class TestNoteModel:
|
||||
html2 = note.html
|
||||
assert html1 == html2
|
||||
|
||||
def test_title_extraction_from_heading(self, tmp_path):
|
||||
"""Test title extraction from markdown heading"""
|
||||
def test_title_is_the_column_not_the_content(self, tmp_path):
|
||||
"""A title comes from notes.title; a heading in the content is just a heading (ADR-076)"""
|
||||
note_file = tmp_path / "notes" / "2024" / "11" / "test.md"
|
||||
note_file.parent.mkdir(parents=True)
|
||||
note_file.write_text("# My Note Title\n\nContent.")
|
||||
|
||||
note = Note(
|
||||
note_file.write_text("# A Heading\n\nContent.")
|
||||
kwargs = dict(
|
||||
id=1,
|
||||
slug="test",
|
||||
file_path="notes/2024/11/test.md",
|
||||
@@ -154,29 +154,13 @@ class TestNoteModel:
|
||||
updated_at=datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
_data_dir=tmp_path,
|
||||
)
|
||||
assert Note(**kwargs).title is None
|
||||
assert "<h1>A Heading</h1>" in Note(**kwargs).html
|
||||
assert Note(**kwargs, title="My Note Title").title == "My Note Title"
|
||||
|
||||
assert note.title == "My Note Title"
|
||||
|
||||
def test_title_extraction_from_first_line(self, tmp_path):
|
||||
"""Test title extraction from first line without heading"""
|
||||
note_file = tmp_path / "notes" / "2024" / "11" / "test.md"
|
||||
note_file.parent.mkdir(parents=True)
|
||||
note_file.write_text("Just a note without heading\n\nMore content.")
|
||||
|
||||
note = Note(
|
||||
id=1,
|
||||
slug="test",
|
||||
file_path="notes/2024/11/test.md",
|
||||
published=True,
|
||||
created_at=datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
updated_at=datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
_data_dir=tmp_path,
|
||||
)
|
||||
|
||||
assert note.title == "Just a note without heading"
|
||||
|
||||
def test_title_fallback_to_slug(self):
|
||||
"""Test title falls back to slug if no content"""
|
||||
def test_label(self, tmp_path):
|
||||
"""label: title, else excerpt, else slug"""
|
||||
assert self._note_with(tmp_path, "Just a note\n\nMore.").label == "Just a note More."
|
||||
note = Note(
|
||||
id=1,
|
||||
slug="my-test-note",
|
||||
@@ -185,10 +169,10 @@ class TestNoteModel:
|
||||
created_at=datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
updated_at=datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
_data_dir=Path("/nonexistent"),
|
||||
title="Titled",
|
||||
)
|
||||
|
||||
# Should fall back to slug (file doesn't exist)
|
||||
assert note.title == "my-test-note"
|
||||
assert note.label == "Titled"
|
||||
assert replace(note, title=None).label == "my-test-note"
|
||||
|
||||
def test_excerpt_generation(self, tmp_path):
|
||||
"""Test excerpt generation"""
|
||||
@@ -208,8 +192,8 @@ class TestNoteModel:
|
||||
)
|
||||
|
||||
excerpt = note.excerpt
|
||||
assert len(excerpt) <= 203 # EXCERPT_LENGTH + "..."
|
||||
assert excerpt.endswith("...")
|
||||
assert len(excerpt) <= 201 # EXCERPT_LENGTH + "…"
|
||||
assert excerpt.endswith("…")
|
||||
|
||||
def test_excerpt_short_content(self, tmp_path):
|
||||
"""Test excerpt with short content (no ellipsis)"""
|
||||
@@ -259,6 +243,24 @@ class TestNoteModel:
|
||||
_data_dir=tmp_path,
|
||||
)
|
||||
|
||||
def test_excerpt_is_plain_text(self, tmp_path):
|
||||
"""No Markdown in previews, alt text or crosspost teasers (v2.16.0)"""
|
||||
note = self._note_with(
|
||||
tmp_path, "Some **bold** and a [link](https://x.example).\n\n\n\n- one\n- two")
|
||||
assert note.excerpt == "Some bold and a link. • one • two"
|
||||
|
||||
def test_hashtag_line_is_not_a_heading(self, tmp_path):
|
||||
"""'#indieweb ...' renders as text; '# Heading' still a heading (v2.16.0)"""
|
||||
note = self._note_with(tmp_path, "#indieweb is fun\n\n##two\n\n# Real heading")
|
||||
assert "<p>#indieweb is fun</p>" in note.html
|
||||
assert "<p>##two</p>" in note.html
|
||||
assert "<h1>Real heading</h1>" in note.html
|
||||
assert note.excerpt.startswith("#indieweb is fun ##two")
|
||||
|
||||
def test_hashtag_in_code_untouched(self, tmp_path):
|
||||
note = self._note_with(tmp_path, "```\n#include <x>\n```")
|
||||
assert "\\" not in note.html and "include" in note.html
|
||||
|
||||
def test_split_title(self):
|
||||
"""A '# Heading' first line is split off as the title"""
|
||||
assert split_title("# My Title\n\nBody") == ("My Title", "Body")
|
||||
@@ -266,22 +268,6 @@ class TestNoteModel:
|
||||
assert split_title("No heading\n# later") == (None, "No heading\n# later")
|
||||
assert split_title("#\nBody") == (None, "#\nBody")
|
||||
|
||||
def test_body_html_leaves_out_title(self, tmp_path):
|
||||
"""Pages show the title themselves, so the body must not repeat it"""
|
||||
note = self._note_with(tmp_path, "# My Title\n\nBody text.")
|
||||
assert "My Title" not in note.body_html
|
||||
assert "<p>Body text.</p>" in note.body_html
|
||||
assert "<h1>My Title</h1>" in note.html # html is unchanged
|
||||
|
||||
def test_body_html_untitled_matches_html(self, tmp_path):
|
||||
note = self._note_with(tmp_path, "Plain note.")
|
||||
assert note.body_html == note.html
|
||||
|
||||
def test_excerpt_leaves_out_title(self, tmp_path):
|
||||
"""Previews show the title above the excerpt, so it is not repeated"""
|
||||
note = self._note_with(tmp_path, "# Title\n\nShort content.")
|
||||
assert note.excerpt == "Short content."
|
||||
|
||||
def test_permalink(self):
|
||||
"""Test permalink generation"""
|
||||
note = Note(
|
||||
|
||||
Reference in new issue
Block a user