fix: Micropub titles, q=source URL, single title display (v2.3.3)
Micropub `name` was dropped; store it as the note's '# Heading' first line, which is how StarPunk titles work. q=source returned /notes/<slug> (a 404) and a name for every note; it now returns the real permalink and name only for titled notes, without the heading in content. Titled notes no longer show their title twice (Note.body_html, excerpt). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c51cf726b0
commit
391bdb9db3
8 files changed
+191
-39
No files matched your search
+33
-3
@@ -43,6 +43,23 @@ MAX_TITLE_LENGTH = 200
|
||||
EXCERPT_LENGTH = 200
|
||||
|
||||
|
||||
def split_title(content: str) -> tuple[Optional[str], str]:
|
||||
"""
|
||||
Split a note's '# Heading' first line (its title, per Q22) off its content
|
||||
|
||||
Returns:
|
||||
(title, remaining content); title is None if the note has no heading
|
||||
"""
|
||||
stripped = content.lstrip()
|
||||
if not stripped.startswith("#"):
|
||||
return None, content
|
||||
first_line, _, rest = stripped.partition("\n")
|
||||
title = first_line.lstrip("#").strip()
|
||||
if not title:
|
||||
return None, content
|
||||
return title, rest.strip()
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Note:
|
||||
"""
|
||||
@@ -244,6 +261,19 @@ class Note:
|
||||
|
||||
return self._cached_html
|
||||
|
||||
@property
|
||||
def body_html(self) -> str:
|
||||
"""
|
||||
Rendered HTML without the title heading
|
||||
|
||||
Pages show a titled note's title as their own heading, so the body
|
||||
leaves it out to avoid showing it twice. Untitled notes: same as html.
|
||||
"""
|
||||
title, body = split_title(self.content)
|
||||
if title is None:
|
||||
return self.html
|
||||
return markdown.markdown(body, extensions=MARKDOWN_EXTENSIONS)
|
||||
|
||||
@property
|
||||
def title(self) -> str:
|
||||
"""
|
||||
@@ -311,10 +341,10 @@ class Note:
|
||||
'This is my note content. It has some interesting points...'
|
||||
"""
|
||||
try:
|
||||
# Get content
|
||||
content = self.content
|
||||
# Leave out the title; previews show it separately
|
||||
_, content = split_title(self.content)
|
||||
|
||||
# Remove markdown heading syntax from first line
|
||||
# Remove markdown heading syntax
|
||||
lines = content.split("\n")
|
||||
cleaned_lines = []
|
||||
for line in lines:
|
||||
|
||||
Reference in new issue
Block a user