示例文章

This commit is contained in:
tangly1024
2022-01-18 16:28:01 +08:00
parent 2a827626bc
commit 59c2224f71
2 changed files with 10 additions and 10 deletions

View File

@@ -13,7 +13,7 @@ const Slug = (props) => {
if (!props.post) {
return <Custom404 />
}
return <LayoutSlug {...props}/>
return <LayoutSlug {...props} />
}
export async function getStaticPaths () {
@@ -45,10 +45,10 @@ export async function getStaticProps ({ params: { slug } }) {
post.blockMap = await getPostBlocks(post.id, 'slug')
// 上一篇、下一篇文章关联
const index = allPosts.indexOf(post)
const prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0]
const next = allPosts.slice(index + 1, index + 2)[0] ?? allPosts[0]
const posts = allPosts.filter(post => post?.type?.[0] === 'Post')
const index = posts.indexOf(post)
const prev = posts.slice(index - 1, index)[0] ?? posts.slice(-1)[0]
const next = posts.slice(index + 1, index + 2)[0] ?? posts[0]
const recommendPosts = getRecommendPost(post, allPosts)
@@ -80,7 +80,7 @@ function getRecommendPost (post, allPosts, count = 5) {
if (post.tags && post.tags.length) {
const currentTag = post.tags[0]
filteredPosts = filteredPosts.filter(
p => p && p.tags && p.tags.includes(currentTag) && p.slug !== post.slug
p => p && p.tags && p.tags.includes(currentTag) && p.slug !== post.slug && p.type === 'post'
)
}
shuffleSort(filteredPosts)

View File

@@ -12,15 +12,15 @@ export default function BlogAround ({ prev, next }) {
return <></>
}
return <section className='text-gray-800 border-t dark:text-gray-300 flex flex-wrap lg:flex-nowrap lg:space-x-10 justify-between py-2'>
<Link href={`/article/${prev.slug}`} passHref>
{prev && <Link href={`/article/${prev.slug}`} passHref>
<a className='text-sm py-3 text-gray-400 hover:underline cursor-pointer'>
<FontAwesomeIcon icon={faAngleDoubleLeft} className='mr-1' />{prev.title}
</a>
</Link>
<Link href={`/article/${next.slug}`} passHref>
</Link>}
{next && <Link href={`/article/${next.slug}`} passHref>
<a className='text-sm flex py-3 text-gray-400 hover:underline cursor-pointer'>{next.title}
<FontAwesomeIcon icon={faAngleDoubleRight} className='ml-1 my-1' />
</a>
</Link>
</Link>}
</section>
}