various fixes
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user