feat(blog): enhance blog data handling with normalization and improved image management
This commit is contained in:
@@ -12,6 +12,28 @@ export const numberToArStyle = (num) => num?.toLocaleString("ar-AE") || "";
|
||||
|
||||
export const isActiveURL = (link, name) => link === name;
|
||||
|
||||
// نگاشت پاسخ API بلاگ (image_url/tags/created_at/body/author-object) به شکلی که
|
||||
// کامپوننتهای بلاگ انتظار دارند (images[{url}]/tag[{name}]/created/body.value/author-string).
|
||||
export const normalizeBlog = (blog) => {
|
||||
if (!blog) return null;
|
||||
return {
|
||||
...blog,
|
||||
images: blog.image_url ? [{ url: blog.image_url }] : [],
|
||||
tag: Array.isArray(blog.tags)
|
||||
? blog.tags.map((t) => (typeof t === "string" ? { name: t } : t))
|
||||
: [],
|
||||
created: blog.created_at ?? blog.created ?? null,
|
||||
body:
|
||||
blog.body && typeof blog.body === "object"
|
||||
? blog.body
|
||||
: { value: blog.body ?? "" },
|
||||
author:
|
||||
blog.author && typeof blog.author === "object"
|
||||
? blog.author.name
|
||||
: blog.author ?? null,
|
||||
};
|
||||
};
|
||||
|
||||
// تبدیل مسیر نسبی تصویر (/uploads/...) به URL کامل backend.
|
||||
// مسیرهای absolute (http...) و asset های محلی (/assets، /default) دستنخورده میمانند.
|
||||
export const imageUrl = (url, fallback = "/assets/images/user.png") => {
|
||||
|
||||
Reference in New Issue
Block a user