From c015a309a1ca9a559fa3b82a6e301ddd21e6d4ab Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sat, 4 Oct 2025 10:57:11 +0000 Subject: [PATCH] Add blog helpers and types cgen-420f34cc5f4c4ff597f662080932f7ea --- client/pages/Blog.tsx | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/client/pages/Blog.tsx b/client/pages/Blog.tsx index b188fffc..9a9c71ea 100644 --- a/client/pages/Blog.tsx +++ b/client/pages/Blog.tsx @@ -26,6 +26,41 @@ import { TrendingUp, } from "lucide-react"; +type BlogPost = { + id?: string | number; + slug?: string; + title: string; + excerpt: string; + author: string; + date: string; + readTime?: string; + category?: string; + image?: string | null; + likes?: number; + comments?: number; + trending?: boolean; +}; + +const normalizeCategory = (value?: string) => + value + ? value + .toString() + .toLowerCase() + .trim() + .replace(/[^a-z0-9]+/g, "-") + .replace(/^-+|-+$/g, "") + : "general"; + +const buildSlug = (post: BlogPost): string => { + const base = (post.slug || post.id || post.title || "").toString(); + const sanitized = base + .trim() + .toLowerCase() + .replace(/[^a-z0-9]+/g, "-") + .replace(/^-+|-+$/g, ""); + return sanitized || "article"; +}; + export default function Blog() { const [isLoading, setIsLoading] = useState(true); const [selectedCategory, setSelectedCategory] = useState("all");