分组-page-nav

This commit is contained in:
tangly1024
2023-06-24 11:27:30 +08:00
parent c14ca330eb
commit 505f713241
2 changed files with 13 additions and 6 deletions

View File

@@ -3,7 +3,7 @@ import Link from 'next/link'
import { useRouter } from 'next/router'
import React from 'react'
const BlogPostCard = ({ post }) => {
const BlogPostCard = ({ post, className }) => {
const router = useRouter()
const currentSelected = router.asPath.split('?')[0] === '/' + post.slug
return (
@@ -13,10 +13,10 @@ const BlogPostCard = ({ post }) => {
href={`${BLOG.SUB_PATH}/${post.slug}`}
passHref
className={
`${currentSelected ? 'bg-gray-500 text-white' : 'text-gray-700 dark:text-gray-300 '} hover:font-bold py-0.5 px-1 text-sm cursor-pointer`
`${className} ${currentSelected ? 'bg-gray-500 text-white' : 'text-gray-700 dark:text-gray-300 '} hover:font-bold py-0.5 cursor-pointer`
}>
<div>
{post.category} - {post.title}
{post.title}
</div>
</Link>

View File

@@ -18,9 +18,16 @@ const BlogPostListScroll = ({ posts = [], currentSearch }) => {
} else {
return <div id='container' ref={targetRef} className='w-full'>
{/* 文章列表 */}
{filteredPosts?.map(post => (
<BlogPostCard key={post.id} post={post} showSummary={true} />
))}
{filteredPosts?.map(group => {
if (group.category) {
return <>
<div className='text-md font-sans ' key={group.category}>{group.category}</div>
{group.items?.map(post => (<div key={post.id} className='pl-6 border-l'><BlogPostCard className='text-sm' post={post} /></div>))}
</>
} else {
return <> {group.items?.map(post => (<BlogPostCard key={post.id} post={post} className='text-md' />))}</>
}
})}
</div>
}
}