所有标签页数量修复
This commit is contained in:
tangly1024
2021-12-01 12:47:17 +08:00
parent 598079869f
commit 633d83beb5
2 changed files with 14 additions and 11 deletions

View File

@@ -30,7 +30,7 @@ export async function getAllTags ({ allPosts, sliceCount = 12, tagOptions }) {
return { name: tag, count: tagObj[tag], color }
})
list.sort((a, b) => b.count - a.count)
if (sliceCount) {
if (sliceCount && sliceCount > 0) {
return list.slice(0, 12)
} else {
return list

View File

@@ -2,17 +2,20 @@ import { getAllCategories, getAllPosts, getAllTags } from '@/lib/notion'
import BLOG from '@/blog.config'
import BaseLayout from '@/layouts/BaseLayout'
import TagItem from '@/components/TagItem'
import { getNotionPageData } from '@/lib/notion/getNotionData'
import { useGlobal } from '@/lib/global'
export default function Tag ({ tags, posts, categories }) {
export default function Tag ({ tags, allPosts, categories }) {
const meta = {
title: `${BLOG.title} | 标签`,
description: BLOG.description,
type: 'website'
}
return <BaseLayout meta={meta} categories={categories} totalPosts={posts}>
const { locale } = useGlobal()
return <BaseLayout meta={meta} categories={categories} totalPosts={allPosts}>
<div className='flex-grow bg-gray-200 dark:bg-black shadow-inner p-10'>
<div className='bg-white dark:bg-gray-700 px-10 py-5 mt-20'>
<div className='dark:text-gray-200 my-5'>所有标签:</div>
<div className='dark:text-gray-200 my-5'>{locale.COMMON.TAGS}:</div>
<div id='tags-list' className='duration-200 flex flex-wrap'>
{
tags.map(tag => {
@@ -26,16 +29,16 @@ export default function Tag ({ tags, posts, categories }) {
}
export async function getStaticProps () {
let posts = await getAllPosts({ from: 'tag-props' })
posts = posts.filter(
post => post.status[0] === 'Published' && post.type[0] === 'Post'
)
const tags = await getAllTags(posts, 0)
const categories = await getAllCategories(posts)
const from = 'tag-index-props'
const notionPageData = await getNotionPageData({ from })
const allPosts = await getAllPosts({ notionPageData, from })
const categories = await getAllCategories(allPosts)
const tagOptions = notionPageData.tagOptions
const tags = await getAllTags({ allPosts, sliceCount: 0, tagOptions })
return {
props: {
tags,
posts,
allPosts,
categories
},
revalidate: 1