feat: Refactor blog components and add pagination

This commit is contained in:
Wini_Fy
2026-02-03 17:05:09 +07:00
parent bf652a64b6
commit 29cc0bf2cd
27 changed files with 2051 additions and 429 deletions

28
utils/image.ts Normal file
View File

@@ -0,0 +1,28 @@
/**
* Build a safe image URL for assets coming from the CMS.
*
* Rules:
* - If already a full URL (http/https) → return as is
* - If starts with `/uploads/` → prepend API URL (NEXT_PUBLIC_API_URL or default localhost)
* - If starts with `/` → use as-is (served by Next/public)
* - Otherwise → treat as relative path under `/`
*/
export function getCmsImageUrl(imagePath: string | undefined): string {
if (!imagePath) return "";
if (imagePath.startsWith("http://") || imagePath.startsWith("https://")) {
return imagePath;
}
if (imagePath.startsWith("/uploads/")) {
const apiUrl = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001";
return `${apiUrl}${imagePath}`;
}
if (imagePath.startsWith("/")) {
return imagePath;
}
return `/${imagePath}`;
}