Wire BlogPost page to Builder CMS
cgen-f46d9cc87ed543389a7b64f959a3b218
This commit is contained in:
parent
8b9988fb40
commit
1ab3d23145
1 changed files with 44 additions and 73 deletions
|
|
@ -1,100 +1,71 @@
|
||||||
import { useMemo } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useParams, Link } from "react-router-dom";
|
import { useParams, Link } from "react-router-dom";
|
||||||
import Layout from "@/components/Layout";
|
import Layout from "@/components/Layout";
|
||||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { User, Calendar } from "lucide-react";
|
import { User, Calendar } from "lucide-react";
|
||||||
import NotFound from "./NotFound";
|
import NotFound from "./NotFound";
|
||||||
|
import { fetchBuilderOne } from "@/lib/builder";
|
||||||
|
|
||||||
export default function BlogPost() {
|
export default function BlogPost() {
|
||||||
const { slug } = useParams<{ slug: string }>();
|
const { slug } = useParams<{ slug: string }>();
|
||||||
|
const [post, setPost] = useState<any | null>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const featuredPost = {
|
useEffect(() => {
|
||||||
title: "The Future of Quantum Game Development",
|
let cancelled = false;
|
||||||
excerpt:
|
(async () => {
|
||||||
"Exploring how quantum computing will revolutionize game AI, physics simulations, and procedural generation in the next decade.",
|
try {
|
||||||
author: "Dr. Sarah Chen",
|
if (!slug) return;
|
||||||
date: "December 15, 2024",
|
const entry = await fetchBuilderOne<any>("blog-post", slug);
|
||||||
readTime: "8 min read",
|
if (!cancelled) setPost(entry?.data ? { ...entry.data, title: entry.data.title || entry.name } : null);
|
||||||
category: "Research",
|
} catch (e) {
|
||||||
likes: 124,
|
console.warn("Builder CMS blog post fetch failed:", e);
|
||||||
comments: 23,
|
} finally {
|
||||||
image:
|
if (!cancelled) setLoading(false);
|
||||||
"https://images.unsplash.com/photo-1635070041078-e363dbe005cb?w=1200&h=600&fit=crop",
|
}
|
||||||
};
|
})();
|
||||||
|
return () => { cancelled = true; };
|
||||||
const posts = [
|
|
||||||
featuredPost,
|
|
||||||
{
|
|
||||||
title: "Building Scalable Game Architecture with Microservices",
|
|
||||||
excerpt:
|
|
||||||
"Learn how to design game backends that can handle millions of concurrent players using modern microservices patterns.",
|
|
||||||
author: "Marcus Rodriguez",
|
|
||||||
date: "December 12, 2024",
|
|
||||||
readTime: "6 min read",
|
|
||||||
category: "Technology",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Advanced Unity Optimization Techniques",
|
|
||||||
excerpt:
|
|
||||||
"Performance optimization strategies that can boost your Unity game's frame rate by up to 300%.",
|
|
||||||
author: "Alex Thompson",
|
|
||||||
date: "December 10, 2024",
|
|
||||||
readTime: "12 min read",
|
|
||||||
category: "Tutorials",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const normalize = (t?: string) =>
|
|
||||||
(t || "")
|
|
||||||
.toLowerCase()
|
|
||||||
.trim()
|
|
||||||
.replace(/[^a-z0-9\s-]/g, "")
|
|
||||||
.replace(/\s+/g, "-")
|
|
||||||
.replace(/-+/g, "-");
|
|
||||||
|
|
||||||
const post = useMemo(() => {
|
|
||||||
if (!slug) return null;
|
|
||||||
return posts.find((p) => normalize(p.title) === normalize(slug));
|
|
||||||
}, [slug]);
|
}, [slug]);
|
||||||
|
|
||||||
if (!post) {
|
if (loading) return null;
|
||||||
return <NotFound />;
|
if (!post) return <NotFound />;
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<div className="min-h-screen bg-aethex-gradient py-12">
|
<div className="min-h-screen bg-aethex-gradient py-12">
|
||||||
<div className="container mx-auto px-4 max-w-3xl">
|
<div className="container mx-auto px-4 max-w-3xl">
|
||||||
<Card className="overflow-hidden border-border/50 animate-scale-in">
|
<Card className="overflow-hidden border-border/50 animate-scale-in">
|
||||||
<img src={post.image} alt={post.title} className="w-full h-64 object-cover" />
|
{post.image && (
|
||||||
|
<img src={post.image} alt={post.title} className="w-full h-64 object-cover" />
|
||||||
|
)}
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<Badge className="mb-4 bg-gradient-to-r from-aethex-500 to-neon-blue">{post.category}</Badge>
|
{post.category && (
|
||||||
|
<Badge className="mb-4 bg-gradient-to-r from-aethex-500 to-neon-blue">{post.category}</Badge>
|
||||||
|
)}
|
||||||
<CardTitle className="text-3xl mt-2">{post.title}</CardTitle>
|
<CardTitle className="text-3xl mt-2">{post.title}</CardTitle>
|
||||||
<CardDescription className="text-muted-foreground mt-2">{post.excerpt}</CardDescription>
|
{post.excerpt && (
|
||||||
|
<CardDescription className="text-muted-foreground mt-2">{post.excerpt}</CardDescription>
|
||||||
|
)}
|
||||||
<div className="flex items-center gap-4 mt-4 text-sm text-muted-foreground">
|
<div className="flex items-center gap-4 mt-4 text-sm text-muted-foreground">
|
||||||
<div className="flex items-center gap-2">
|
{post.author && (
|
||||||
<User className="h-4 w-4" /> <span>{post.author}</span>
|
<div className="flex items-center gap-2">
|
||||||
</div>
|
<User className="h-4 w-4" /> <span>{post.author}</span>
|
||||||
<div className="flex items-center gap-2">
|
</div>
|
||||||
<Calendar className="h-4 w-4" /> <span>{post.date}</span>
|
)}
|
||||||
</div>
|
{post.date && (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Calendar className="h-4 w-4" /> <span>{post.date}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="prose max-w-none mt-6">
|
<CardContent className="prose max-w-none mt-6">
|
||||||
{/* Simple placeholder content for the article body */}
|
{post.body ? (
|
||||||
<p>
|
<div dangerouslySetInnerHTML={{ __html: post.body }} />
|
||||||
{post.excerpt}
|
) : (
|
||||||
</p>
|
<p>{post.excerpt}</p>
|
||||||
|
)}
|
||||||
<p>
|
|
||||||
This is a sample article page. In production the blog content would be loaded from the CMS or database and rendered here.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<strong>Author:</strong> {post.author}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div className="pt-6">
|
<div className="pt-6">
|
||||||
<Link to="/blog" className="text-aethex-400 underline">Back to Blog</Link>
|
<Link to="/blog" className="text-aethex-400 underline">Back to Blog</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue