This commit is contained in:
m
2026-03-26 16:09:38 +01:00
parent a47ad949bd
commit f3ff920e38

View File

@@ -92,4 +92,37 @@ def collect_css(context):
if css:
css_files.append(css)
return css_files
return css_files
def generate_preview(content, max_length=200):
if isinstance(content, str):
# old system
text = re.sub(r"<[^>]+>", "", content) # strip HTML
return text[:max_length]
elif isinstance(content, list):
# new system
for block in content:
if block.get("type") == "text":
text = re.sub(r"<[^>]+>", "", block.get("value", ""))
return text[:max_length]
return ""
# optinal, for images
def generate_preview_html(content, context=None):
if isinstance(content, list):
for block in content:
if block.get("type") == "text":
return f"<div class='blog-preview'>{block.get('value')}</div>"
elif block.get("type") in COMPONENTS:
# optional: allow image preview
render_func = COMPONENTS[block["type"]]["render"]
kwargs = {k: v for k, v in block.items() if k != "type"}
return render_func(**kwargs, context=context)
elif isinstance(content, str):
return content[:200]
return ""