feat: add content_preview helper and apply rendered content across templates

Introduce a new `content_preview()` function in `rendering.py` that strips HTML from rendered content and truncates to a given length with an ellipsis. Add a corresponding `plainText()` and `preview()` method to the `ContentRenderer` JS class. Register `content_preview` as a Jinja2 global in `templating.py`. Update multiple templates (`feed.html`, `gists.html`, `landing.html`, `messages.html`, `news.html`, `notifications.html`, `post.html`, `profile.html`) to use `render_title`, `render_content`, or `content_preview` instead of raw string slicing, ensuring consistent rendering of rich text (e.g., Markdown, HTML) in previews, descriptions, bios, and notification messages. Also fix the conversation preview in `MessagesLayout.js` to use the new JS preview method.
This commit is contained in:
2026-06-22 21:17:54 +00:00
parent e0e64c8d9e
commit c9a4a4b280
12 changed files with 46 additions and 15 deletions
+11
View File
@@ -255,3 +255,14 @@ def render_title(text) -> Markup:
if not text:
return Markup("")
return Markup(_render_title(str(text)))
def content_preview(text, length: int = 60) -> str:
if not text:
return ""
from devplacepy.utils import strip_html
plain = strip_html(_render_content(str(text)))
if len(plain) <= length:
return plain
return plain[:length].rstrip() + "..."