diff --git a/app/a/[slug]/BlogPostClient.tsx b/app/a/[slug]/BlogPostClient.tsx index 3af4a8c..bd37a40 100644 --- a/app/a/[slug]/BlogPostClient.tsx +++ b/app/a/[slug]/BlogPostClient.tsx @@ -6,7 +6,7 @@ import { ArrowLeft, Calendar, User } from "lucide-react" import Image from "next/image" import { MarkdownRenderer } from "@/lib/markdown-renderer" import Footer from "@/components/footer" -import { BlogPost } from "@/lib/blog" +import type { BlogPost } from "@/types/blog" export default function BlogPostPage({ post }: { post: BlogPost }) { const [copied, setCopied] = useState(false) diff --git a/app/page.tsx b/app/page.tsx index af58c9a..e574f52 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -7,28 +7,12 @@ import BlogCard from "@/components/blog-card" import Pagination from "@/components/pagination" import Link from "next/link" import Footer from "@/components/footer" - -interface BlogPost { - slug: string - title: string - author: string - date: string - image: string - excerpt: string - featured: boolean -} - -interface PaginatedData { - posts: BlogPost[] - totalPages: number - hasNextPage: boolean - hasPrevPage: boolean -} +import type { PaginatedPosts } from "@/types/blog" export default function HomePage() { const router = useRouter() const searchParams = useSearchParams() - const [paginatedData, setPaginatedData] = useState(null) + const [paginatedData, setPaginatedData] = useState(null) const [loading, setLoading] = useState(true) const [currentPage, setCurrentPage] = useState(1) diff --git a/components/blog-card.tsx b/components/blog-card.tsx index a74b383..299bd48 100644 --- a/components/blog-card.tsx +++ b/components/blog-card.tsx @@ -1,16 +1,7 @@ import Image from "next/image" import Link from "next/link" import { User, Star } from "lucide-react" - -interface BlogPost { - slug: string - title: string - author: string - date: string - image: string - excerpt: string - featured: boolean -} +import type { BlogPost } from "@/types/blog" interface BlogCardProps { post: BlogPost diff --git a/lib/blog-server.ts b/lib/blog-server.ts index a46d598..9f03cae 100644 --- a/lib/blog-server.ts +++ b/lib/blog-server.ts @@ -2,17 +2,7 @@ import { readFileSync, existsSync } from 'fs' import { join } from 'path' import matter from 'gray-matter' import articlesIndex from '../public/articles/articles-index.json' - -export interface BlogPost { - slug: string - title: string - author: string - date: string - image: string - excerpt: string - content: string - featured: boolean -} +import type { BlogPost } from '@/types/blog' // Server-side function to get post by slug with actual markdown content export function getPostBySlugServer(slug: string): BlogPost | null { diff --git a/lib/blog.ts b/lib/blog.ts index d7d7025..6e731be 100644 --- a/lib/blog.ts +++ b/lib/blog.ts @@ -1,15 +1,5 @@ import articlesIndex from '../public/articles/articles-index.json' - -export interface BlogPost { - slug: string - title: string - author: string - date: string - image: string - excerpt: string - content: string - featured: boolean -} +import type { BlogPost, PaginatedPosts } from '@/types/blog' // Get all posts from articles index (client-safe) export function getAllPosts(): BlogPost[] { @@ -39,13 +29,7 @@ export function getPostBySlug(slug: string): BlogPost | null { export function getPaginatedPosts( page = 1, limit = 6, -): { - posts: BlogPost[] - totalPages: number - currentPage: number - hasNextPage: boolean - hasPrevPage: boolean -} { +): PaginatedPosts { const allPosts = getAllPosts() const totalPosts = allPosts.length const totalPages = Math.ceil(totalPosts / limit) diff --git a/types/blog.ts b/types/blog.ts new file mode 100644 index 0000000..0e075b3 --- /dev/null +++ b/types/blog.ts @@ -0,0 +1,18 @@ +export interface BlogPost { + slug: string + title: string + author: string + date: string + image: string + excerpt: string + content: string + featured: boolean +} + +export interface PaginatedPosts { + posts: BlogPost[] + totalPages: number + currentPage: number + hasNextPage: boolean + hasPrevPage: boolean +}