--- import { createMarkdownRenderer } from "@/utils"; import { POSTS_API } from "@/data/constants"; const md = await createMarkdownRenderer(); interface Post { short_id: string; title: string | null; slug: string; published_date: string | null; meta_description: string | null; meta_image: string | null; canonical_url: string | null; lang: string; tags: string | null; content: string; created_at: string; updated_at: string; } interface PostsListResponse { posts: Post[]; } let posts: Post[] = []; let error = false; try { const res = await fetch(`${POSTS_API}/posts`); if (res.ok) { const data = (await res.json()) as PostsListResponse; posts = (data.posts || []).slice().sort((a, b) => { const dateA = a.published_date ? new Date(a.published_date).getTime() : 0; const dateB = b.published_date ? new Date(b.published_date).getTime() : 0; return dateB - dateA; }); } else { error = true; } } catch (err) { console.error("Error fetching updates:", err); error = true; } --- {error &&

Error loading recent updates.

} {!error && posts.length === 0 &&

No recent updates found.

} {!error && posts.length > 0 && (
{posts.map((post) => { const publishedAt = post.published_date ? new Date(post.published_date).toLocaleDateString() : ""; const contentHTML = post.content ? md.render(post.content).trim() .replace(/]*?)>/g, (_, attrs) => { const hasLoading = /loading\s*=/.test(attrs); const hasDecoding = /decoding\s*=/.test(attrs); const hasWidth = /width\s*=/.test(attrs); const extra = `${hasLoading ? "" : ' loading="lazy"'}${hasDecoding ? "" : ' decoding="async"'}${hasWidth ? "" : ' width="800"'}`; return ``; }) : ""; return ( ); })}
)}