Files
nobat724_front/lib/sanitize.js
T
hamed cea8982e6d feat: add script to generate default blog cover image
- Introduced a new script `make-blog-cover.mjs` to create a default cover image for blog posts.
- The image is generated in PNG format with dimensions 1200x630, suitable for Open Graph.
- Utilizes the site's branding colors and logo from `public/nobat724.svg`.
- Includes custom font styling using the Vazirmatn font.
- The generated image is saved to `public/assets/images/blog-default-cover.png`.
2026-07-27 19:07:30 +03:30

37 lines
1.6 KiB
JavaScript

import DOMPurify from "isomorphic-dompurify";
export function sanitizeHtml(html) {
if (!html || typeof html !== "string") return "";
// ⚠️ ALLOWED_TAGS اینجا با `clinicpro-crawler/content/composer.py` (ثابت
// ALLOWED_TAGS) آینه است: مولد محتوا فقط همین تگ‌ها را تولید می‌کند. اگر این
// فهرست را تغییر دادی، آن‌جا را هم تغییر بده — وگرنه محتوای تولیدشده بی‌صدا
// از صفحه حذف می‌شود. توجه: class و style در ALLOWED_ATTR نیستند.
return DOMPurify.sanitize(html, {
ALLOWED_TAGS: [
"p", "br", "strong", "em", "b", "i", "u", "ul", "ol", "li", "a",
"h2", "h3", "h4", "h5", "blockquote", "img", "span", "div",
"table", "thead", "tbody", "tr", "td", "th",
// خروجی CKEditor پنل ادمین جدول و تصویر را داخل <figure> می‌گذارد؛ بدون
// این دو، wrapper حذف و figcaption (متن زیر تصویر) کاملاً گم می‌شد.
"figure", "figcaption",
],
ALLOWED_ATTR: ["href", "target", "rel", "src", "alt", "title"],
ALLOW_DATA_ATTR: false,
});
}
// خروجی امن برای <script type="application/ld+json"> — جلوگیری از بستن تگ با داده‌ی کاربر
export function safeJsonLd(obj) {
return JSON.stringify(obj).replace(/</g, "\\u003c");
}
export function safeJsonParse(str, fallback = null) {
if (!str) return fallback;
try {
return JSON.parse(str);
} catch {
return fallback;
}
}