From 98071855679991b5ef7ff20f2aa64668c0f4010e Mon Sep 17 00:00:00 2001 From: ahaapple Date: Tue, 5 Nov 2024 21:37:08 +0800 Subject: [PATCH] Update blog page UI with pagegen ai --- .../app/[locale]/(marketing)/blog/page.tsx | 2 +- frontend/components/blog-posts.tsx | 52 ----------------- frontend/components/blog/blog-card.tsx | 52 +++++++++++++++++ frontend/components/blog/blog-posts.tsx | 30 ++++++++++ frontend/components/blog/latest-blog-card.tsx | 57 +++++++++++++++++++ frontend/components/blog/random-image.ts | 13 +++++ 6 files changed, 153 insertions(+), 53 deletions(-) delete mode 100644 frontend/components/blog-posts.tsx create mode 100644 frontend/components/blog/blog-card.tsx create mode 100644 frontend/components/blog/blog-posts.tsx create mode 100644 frontend/components/blog/latest-blog-card.tsx create mode 100644 frontend/components/blog/random-image.ts diff --git a/frontend/app/[locale]/(marketing)/blog/page.tsx b/frontend/app/[locale]/(marketing)/blog/page.tsx index 2aee3b4a..86d5362b 100644 --- a/frontend/app/[locale]/(marketing)/blog/page.tsx +++ b/frontend/app/[locale]/(marketing)/blog/page.tsx @@ -1,7 +1,7 @@ import { allPosts } from 'contentlayer/generated'; import { compareDesc } from 'date-fns'; -import { BlogPosts } from '@/components/blog-posts'; +import { BlogPosts } from '@/components/blog/blog-posts'; import { siteConfig } from '@/config'; import { unstable_setRequestLocale } from 'next-intl/server'; import { type Locale } from '@/i18n/routing'; diff --git a/frontend/components/blog-posts.tsx b/frontend/components/blog-posts.tsx deleted file mode 100644 index 9b50f9a9..00000000 --- a/frontend/components/blog-posts.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { formatDate } from '@/lib/utils'; -import Image from 'next/image'; -import Link from 'next/link'; - -export function BlogPosts({ posts }) { - return ( -
-
-

Last Post

-
-
- {posts[0].image && ( - {posts[0].title} - )} -
-
-

{posts[0].title}

- {posts[0].description &&

{posts[0].description}

} - - View Article - -
-
-
- -
-

Blog Posts

-
- {posts.slice(1).map((post) => ( -
- {post.image && ( - {post.title} - )} -

{post.title}

- {post.description &&

{post.description}

} - {post.date &&

{formatDate(post.date)}

} - - View Article - -
- ))} -
-
-
- ); -} diff --git a/frontend/components/blog/blog-card.tsx b/frontend/components/blog/blog-card.tsx new file mode 100644 index 00000000..47308130 --- /dev/null +++ b/frontend/components/blog/blog-card.tsx @@ -0,0 +1,52 @@ +'use client'; + +import { motion } from 'framer-motion'; +import { Calendar, Clock } from 'lucide-react'; +import { Card, CardContent } from '@/components/ui/card'; +import Link from 'next/link'; +import { getRandomImage } from '@/components/blog/random-image'; + +interface BlogCardProps { + href: string; + title: string; + description: string; + date: string; + readTime?: string; +} + +export default function BlogCard({ href, title, description, date, readTime = '5 min read' }: BlogCardProps) { + return ( + + + +
+ {title} +
+ + +

+ {title} +

+ +

{description}

+ +
+
+ + {date} +
+
+ + {readTime} +
+
+
+
+
+ + ); +} diff --git a/frontend/components/blog/blog-posts.tsx b/frontend/components/blog/blog-posts.tsx new file mode 100644 index 00000000..b5117f0d --- /dev/null +++ b/frontend/components/blog/blog-posts.tsx @@ -0,0 +1,30 @@ +import BlogCard from '@/components/blog/blog-card'; +import LatestBlogCard from '@/components/blog/latest-blog-card'; +import { formatDate } from '@/lib/utils'; + +export function BlogPosts({ posts }) { + const latestPost = posts[0]; + return ( +
+
+

Latest Post

+ +
+ +
+

Blog Posts

+
+ {posts.slice(1).map((post) => ( + + ))} +
+
+
+ ); +} diff --git a/frontend/components/blog/latest-blog-card.tsx b/frontend/components/blog/latest-blog-card.tsx new file mode 100644 index 00000000..fe1aa8cd --- /dev/null +++ b/frontend/components/blog/latest-blog-card.tsx @@ -0,0 +1,57 @@ +'use client'; + +import { motion } from 'framer-motion'; +import { Calendar, Clock } from 'lucide-react'; +import { Card, CardContent } from '@/components/ui/card'; +import Link from 'next/link'; +import { getRandomImage } from '@/components/blog/random-image'; + +interface LastBlogCardProps { + href: string; + title: string; + description: string; + date: string; + readTime?: string; +} + +export default function LatestBlogCard({ href, title, description, date, readTime = '8 min read' }: LastBlogCardProps) { + return ( + + + + +
+
+ {title} +
+ +
+
+

+ {title} +

+ +

{description}

+
+
+
+ + {date} +
+
+ + {readTime} +
+
+
+
+
+
+
+ + ); +} diff --git a/frontend/components/blog/random-image.ts b/frontend/components/blog/random-image.ts new file mode 100644 index 00000000..c8d20413 --- /dev/null +++ b/frontend/components/blog/random-image.ts @@ -0,0 +1,13 @@ +const imageList = [ + 'https://images.unsplash.com/photo-1616071906060-1f425a639465', + 'https://images.unsplash.com/photo-1643986149937-5d0b9306dba5', + 'https://images.unsplash.com/photo-1629140476584-f10ee7810d2c', + 'https://images.unsplash.com/photo-1608501712351-a4ca8dc996fb', + 'https://images.unsplash.com/photo-1495785870240-c8456d5aeda2', + 'https://images.unsplash.com/photo-1616071906060-1f425a639465', +]; + +export const getRandomImage = () => { + const randomIndex = Math.floor(Math.random() * imageList.length); + return imageList[randomIndex]; +};