import Link from '@/components/Link' import Tag from '@/components/Tag' import siteMetadata from '@/data/siteMetadata' import { useState } from 'react' import Pagination from '@/components/Pagination' const postDateTemplate = { year: 'numeric', month: 'long', day: 'numeric' } export default function ListLayout({ posts, title, initialDisplayPosts = [], pagination }) { const [searchValue, setSearchValue] = useState('') const filteredBlogPosts = posts.filter((frontMatter) => { const searchContent = frontMatter.title + frontMatter.summary + frontMatter.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}

setSearchValue(e.target.value)} placeholder="Search articles" className="block w-full px-4 py-2 text-gray-900 bg-white border border-gray-300 rounded-md dark:border-gray-900 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-800 dark:text-gray-100" />
{pagination && pagination.totalPages > 1 && !searchValue && ( )} ) }