| import { X } from "@/components/icons/X"; | |
| // src/pages/BlogPostPage.tsx | |
| import { useParams, Link } from "react-router-dom"; | |
| import { motion } from "framer-motion"; | |
| import { useBlogPost, useBlogCategories, useBlogTags } from "@/hooks/useBlog"; | |
| import { BlogSidebar } from "@/components/blog/BlogSidebar"; | |
| import { BlogAuthor } from "@/components/blog/BlogAuthor"; | |
| import { BlogComments } from "@/components/blog/BlogComments"; | |
| import { BlogRelated } from "@/components/blog/BlogRelated"; | |
| import { BlogTableOfContents } from "@/components/blog/BlogTableOfContents"; | |
| import { LoadingSpinner } from "@/components/common/LoadingSpinner"; | |
| import { toast } from "react-toastify"; | |
| import { useState } from "react"; | |
| import { ArrowLeft, Calendar, Clock, Eye, Heart, MessageCircle, Bookmark, Check, Copy } from "lucide-react"; | |
| const BlogCommentsAny = BlogComments as any; | |
| const BlogRelatedAny = BlogRelated as any; | |
| const BlogTableOfContentsAny = BlogTableOfContents as any; | |
| export default function BlogPostPage() { | |
| const params = useParams<{ slug?: string; id?: string }>(); | |
| const slug = params.slug || params.id || ""; | |
| const { post, loading, error } = useBlogPost(slug); | |
| const { categories } = useBlogCategories(); | |
| const { tags } = useBlogTags(); | |
| const [copied, setCopied] = useState(false); | |
| const handleCopyLink = () => { | |
| navigator.clipboard.writeText(window.location.href); | |
| setCopied(true); | |
| toast.success("Link copied!"); | |
| setTimeout(() => setCopied(false), 2000); | |
| }; | |
| if (loading) { | |
| return ( | |
| <div className="min-h-screen flex items-center justify-center"> | |
| <LoadingSpinner size="lg" /> | |
| </div> | |
| ); | |
| } | |
| if (error || !post) { | |
| return ( | |
| <div className="min-h-screen flex items-center justify-center"> | |
| <div className="text-center"> | |
| <h1 className="text-2xl font-bold mb-2">Post Not Found</h1> | |
| <p className="text-gray-500 mb-4">The blog post you're looking for doesn't exist.</p> | |
| <Link to="/blog" className="text-primary hover:underline">← Back to Blog</Link> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| return ( | |
| <div className="min-h-screen bg-gray-50 dark:bg-gray-900"> | |
| <div className="container mx-auto px-4 py-8"> | |
| {/* Back Button */} | |
| <Link to="/blog" className="inline-flex items-center gap-2 text-gray-500 hover:text-primary transition mb-6 group"> | |
| <ArrowLeft className="h-4 w-4 group-hover:-translate-x-1 transition" /> | |
| Back to Blog | |
| </Link> | |
| <div className="grid gap-8 lg:grid-cols-3"> | |
| {/* Main Content */} | |
| <div className="lg:col-span-2"> | |
| <motion.article | |
| initial={{ opacity: 0, y: 20 }} | |
| animate={{ opacity: 1, y: 0 }} | |
| className="bg-white dark:bg-gray-800 rounded-2xl shadow-sm overflow-hidden" | |
| > | |
| {/* Cover Image */} | |
| <div className="relative h-96 overflow-hidden"> | |
| <img src={post.coverImage} alt={post.title} className="w-full h-full object-cover" /> | |
| {post.featured && ( | |
| <div className="absolute top-4 left-4"> | |
| <span className="px-2 py-1 text-xs font-semibold bg-yellow-500 text-black rounded-full">Featured</span> | |
| </div> | |
| )} | |
| </div> | |
| {/* Content */} | |
| <div className="p-6 md:p-8"> | |
| {/* Categories */} | |
| <div className="flex flex-wrap gap-2 mb-4"> | |
| {(post.categories ?? []).map((cat) => ( | |
| <Link key={cat.id} to={`/blog?category=${cat.slug}`} className="px-2 py-1 text-xs rounded-full bg-primary/10 text-primary hover:bg-primary/20 transition"> | |
| {cat.name} | |
| </Link> | |
| ))} | |
| </div> | |
| {/* Title */} | |
| <h1 className="text-3xl md:text-4xl lg:text-5xl font-bold mb-4">{post.title}</h1> | |
| {/* Meta Info */} | |
| <div className="flex flex-wrap items-center gap-4 text-sm text-gray-500 mb-6 pb-6 border-b border-gray-200 dark:border-gray-700"> | |
| <span className="flex items-center gap-1"><Calendar className="h-4 w-4" /> {new Date(post.publishedAt ?? post.createdAt).toLocaleDateString()}</span> | |
| <span className="flex items-center gap-1"><Clock className="h-4 w-4" /> {post.readTime ?? 0} min read</span> | |
| <span className="flex items-center gap-1"><Eye className="h-4 w-4" /> {(post.views ?? 0).toLocaleString()} views</span> | |
| </div> | |
| {/* Table of Contents */} | |
| {post.tableOfContents && post.tableOfContents.length > 0 && ( | |
| <BlogTableOfContentsAny items={post.tableOfContents} /> | |
| )} | |
| {/* Content */} | |
| <div | |
| className="prose prose-lg dark:prose-invert max-w-none mb-8" | |
| dangerouslySetInnerHTML={{ __html: post.content ?? "" }} | |
| /> | |
| {/* Tags */} | |
| {(post.tags ?? []).length > 0 && ( | |
| <div className="mb-6"> | |
| <h3 className="text-sm font-semibold mb-2">Tags</h3> | |
| <div className="flex flex-wrap gap-2"> | |
| {(post.tags ?? []).map((tag) => ( | |
| <Link key={tag.id} to={`/blog?tag=${tag.slug}`} className="px-3 py-1 text-sm rounded-full bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 hover:bg-primary hover:text-white transition"> | |
| #{tag.name} | |
| </Link> | |
| ))} | |
| </div> | |
| </div> | |
| )} | |
| {/* Share & Actions */} | |
| <div className="flex flex-wrap items-center justify-between gap-4 py-4 border-t border-gray-200 dark:border-gray-700"> | |
| <div className="flex items-center gap-2"> | |
| <button className="flex items-center gap-1 px-3 py-1.5 rounded-full bg-red-50 dark:bg-red-900/20 text-red-500 hover:bg-red-100 transition"> | |
| <Heart className="h-4 w-4" /> {post.likes ?? 0} | |
| </button> | |
| <button className="flex items-center gap-1 px-3 py-1.5 rounded-full bg-blue-50 dark:bg-blue-900/20 text-blue-500 hover:bg-blue-100 transition"> | |
| <MessageCircle className="h-4 w-4" /> {post.comments ?? 0} | |
| </button> | |
| <button className="flex items-center gap-1 px-3 py-1.5 rounded-full bg-yellow-50 dark:bg-yellow-900/20 text-yellow-500 hover:bg-yellow-100 transition"> | |
| <Bookmark className="h-4 w-4" /> Save | |
| </button> | |
| </div> | |
| <div className="flex items-center gap-2"> | |
| <a href={`https://twitter.com/intent/tweet?text=${encodeURIComponent(post.title)}&url=${encodeURIComponent(window.location.href)}`} target="_blank" rel="noopener noreferrer" className="p-2 rounded-full bg-gray-100 dark:bg-gray-700 text-gray-600 hover:bg-[#1DA1F2] hover:text-white transition"> | |
| <X className="h-4 w-4" /> | |
| </a> | |
| <a href={`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(window.location.href)}`} target="_blank" rel="noopener noreferrer" className="p-2 rounded-full bg-gray-100 dark:bg-gray-700 text-gray-600 hover:bg-[#0077B5] hover:text-white transition"> | |
| </a> | |
| <button onClick={handleCopyLink} className="p-2 rounded-full bg-gray-100 dark:bg-gray-700 text-gray-600 hover:bg-primary hover:text-white transition"> | |
| {copied ? <Check className="h-4 w-4" /> : <Copy className="h-4 w-4" />} | |
| </button> | |
| </div> | |
| </div> | |
| {/* Author Section */} | |
| <div className="mt-6"> | |
| <BlogAuthor author={post.author} showBio showStats variant="horizontal" /> | |
| </div> | |
| {/* Comments */} | |
| <BlogCommentsAny postId={post.id} /> | |
| </div> | |
| </motion.article> | |
| </div> | |
| {/* Sidebar */} | |
| <div> | |
| <BlogSidebar categories={categories} tags={tags} showNewsletter={true} /> | |
| </div> | |
| </div> | |
| {/* Related Posts */} | |
| <BlogRelatedAny currentPostId={post.id} categoryId={post.categories?.[0]?.id} /> | |
| </div> | |
| </div> | |
| ); | |
| } | |
Xet Storage Details
- Size:
- 8.57 kB
- Xet hash:
- afec677523e5296d8233a59bc3a4bf52f28dd093c033a8593f37536d06a501d7
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.