fix(blog): پاک‌ساز سمت سرور — پاراگراف‌های خالی/nbsp داخل نقل‌قول در هر ذخیره حذف می‌شوند

This commit is contained in:
aramesh-site deploy
2026-10-06 11:51:22 +00:00
parent f05cd8b820
commit 2556bbfa1b
+18
View File
@@ -29,6 +29,21 @@ def _clean_url(value: Any) -> str | None:
return stripped return stripped
def _is_junk_paragraph(node: Any) -> bool:
"""پاراگراف خالی یا فقط نویسهٔ خنثی (nbsp/فاصله) — داخل نقل‌قول حذف می‌شود."""
if not isinstance(node, dict) or node.get("type") != "paragraph":
return False
content = node.get("content") or []
if not content:
return True
return all(
isinstance(item, dict)
and item.get("type") == "text"
and not str(item.get("text", "")).replace("\xa0", " ").strip()
for item in content
)
def _walk(node: Any) -> Any: def _walk(node: Any) -> Any:
if isinstance(node, list): if isinstance(node, list):
return [_walk(item) for item in node] return [_walk(item) for item in node]
@@ -48,6 +63,9 @@ def _walk(node: Any) -> Any:
cleaned[key] = attrs cleaned[key] = attrs
else: else:
cleaned[key] = _walk(value) cleaned[key] = _walk(value)
# داخل نقل‌قول: پاراگراف‌های خالی/نویسهٔ خنثی حذف — وگرنه خط خالی اضافه رندر می‌شود
if cleaned.get("type") == "blockquote" and isinstance(cleaned.get("content"), list):
cleaned["content"] = [c for c in cleaned["content"] if not _is_junk_paragraph(c)]
return cleaned return cleaned