From b797f6b9b36fc37909e455d97c5e990c4f018460 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Fri, 28 Feb 2025 02:12:20 -0600 Subject: [PATCH] refactor: extract BlogPostCard component and improve image handling --- .../[locale]/blog/components/BlogPostCard.tsx | 25 +++-- apps/website/app/[locale]/blog/page.tsx | 97 +------------------ 2 files changed, 16 insertions(+), 106 deletions(-) diff --git a/apps/website/app/[locale]/blog/components/BlogPostCard.tsx b/apps/website/app/[locale]/blog/components/BlogPostCard.tsx index 9b38222..5fe5659 100644 --- a/apps/website/app/[locale]/blog/components/BlogPostCard.tsx +++ b/apps/website/app/[locale]/blog/components/BlogPostCard.tsx @@ -16,22 +16,25 @@ export function BlogPostCard({ post, locale }: BlogPostCardProps) { day: "numeric", }); + const handleTwitterClick = (e: React.MouseEvent) => { + e.preventDefault(); + e.stopPropagation(); + }; + return (
- {post.feature_image && ( -
- {post.title} -
- )} +
+ {post.feature_image +

{post.title} @@ -49,6 +52,7 @@ export function BlogPostCard({ post, locale }: BlogPostCardProps) { target="_blank" rel="noopener noreferrer" className="block cursor-pointer transition-opacity hover:opacity-90" + onClick={handleTwitterClick} > {post.primary_author.name || "Unknown Author"} diff --git a/apps/website/app/[locale]/blog/page.tsx b/apps/website/app/[locale]/blog/page.tsx index 2481da7..498120d 100644 --- a/apps/website/app/[locale]/blog/page.tsx +++ b/apps/website/app/[locale]/blog/page.tsx @@ -3,8 +3,8 @@ import type { Post } from "@/lib/ghost"; import { RssIcon } from "lucide-react"; import type { Metadata } from "next"; import { getTranslations } from "next-intl/server"; -import Image from "next/image"; import Link from "next/link"; +import { BlogPostCard } from "./components/BlogPostCard"; import { SearchAndFilter } from "./components/SearchAndFilter"; interface Tag { @@ -18,8 +18,6 @@ export const metadata: Metadata = { description: "Latest news, updates, and articles from Dokploy", }; -export const revalidate = 3600; // Revalidate the data at most every hour - export default async function BlogPage({ params: { locale }, searchParams, @@ -88,96 +86,3 @@ export default async function BlogPage({

); } - -function BlogPostCard({ post, locale }: { post: Post; locale: string }) { - const formattedDate = new Date(post.published_at).toLocaleDateString(locale, { - year: "numeric", - month: "long", - day: "numeric", - }); - - return ( - -
- {post.feature_image ? ( -
- {post.title} -
- ) : ( -
- Default Image -
- )} -
-

- {post.title} -

-

- {post.custom_excerpt || post.excerpt} -

-
-
- {post.primary_author?.profile_image && ( -
- {post.primary_author.twitter ? ( - - {post.primary_author.name} - - ) : ( - {post.primary_author.name} - )} -
- )} - {post.primary_author?.twitter ? ( - - {post.primary_author.name || "Unknown Author"} - - ) : ( - {post.primary_author?.name || "Unknown Author"} - )} -
- in - {post.primary_tag?.name || "General"} - - {post.reading_time} min read - - {formattedDate} -
-
-
- - ); -}