Add blog helpers and types
cgen-420f34cc5f4c4ff597f662080932f7ea
This commit is contained in:
parent
caf73bf833
commit
c015a309a1
1 changed files with 35 additions and 0 deletions
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Reference in a new issue