Add blog helpers and types

cgen-420f34cc5f4c4ff597f662080932f7ea
This commit is contained in:
Builder.io 2025-10-04 10:57:11 +00:00
parent caf73bf833
commit c015a309a1

View file

@ -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");