'use client'; import { useState } from 'react'; import { usePathname } from 'next/navigation'; import { formatDate } from 'pliny/utils/formatDate'; import { CoreContent } from 'pliny/utils/contentlayer'; import type { Blog } from 'contentlayer/generated'; import Link from '@/components/Link'; import Tag from '@/components/Tag'; import siteMetadata from '@/data/siteMetadata'; interface PaginationProps { totalPages: number; currentPage: number; } interface ListLayoutProps { posts: CoreContent[]; title: string; initialDisplayPosts?: CoreContent[]; pagination?: PaginationProps; } function Pagination({ totalPages, currentPage }: PaginationProps) { const pathname = usePathname(); const basePath = pathname.split('/')[1]; const prevPage = currentPage - 1 > 0; const nextPage = currentPage + 1 <= totalPages; return (
); } export default function ListLayout({ posts, title, initialDisplayPosts = [], pagination, }: ListLayoutProps) { const [searchValue, setSearchValue] = useState(''); const filteredBlogPosts = posts.filter((post) => { const searchContent = post.title + post.summary + post.tags?.join(' '); return searchContent.toLowerCase().includes(searchValue.toLowerCase()); }); // If initialDisplayPosts exist, display it if no searchValue is specified const displayPosts = initialDisplayPosts.length > 0 && !searchValue ? initialDisplayPosts : filteredBlogPosts; return ( <>

{title}

    {!filteredBlogPosts.length && 'No posts found.'} {displayPosts.map((post) => { const { path, date, title, summary, tags } = post; return (
  • Published on

    {title}

    {tags?.map((tag) => )}
    {summary}
  • ); })}
{pagination && pagination.totalPages > 1 && !searchValue && ( )} ); }