various fixes

This commit is contained in:
2026-09-24 08:28:43 -07:00
parent 92883d63f5
commit 720ffca099
7 changed files with 119 additions and 6 deletions

View File

@@ -48,6 +48,24 @@ def note_attachments(body: str) -> tuple[int, str | None]:
return count, preview
def note_snippet(body: str, limit: int = 240) -> str:
lines = body.splitlines()
start = 0
for i, line in enumerate(lines):
stripped = line.strip()
if not stripped:
continue
if stripped.startswith("# "):
start = i + 1
continue
start = i
break
excerpt = "\n".join(lines[start:]).strip()
if len(excerpt) > limit:
excerpt = excerpt[:limit].rstrip() + "…"
return excerpt
def note_path(username: str, note_id: str) -> str:
return f"{username}/{note_id}.md"
@@ -293,6 +311,7 @@ async def _attach_meta(notes: list[dict]) -> None:
count, preview = 0, None
note["attachments"] = count
note["image"] = preview
note["snippet"] = note_snippet(body)
note.pop("path", None)