修复部分NOTION_CONFIG读取问题

This commit is contained in:
tangly1024.com
2024-05-15 14:55:14 +08:00
parent 70e53649b3
commit 517a967640
44 changed files with 911 additions and 565 deletions

View File

@@ -1,10 +1,10 @@
import { siteConfig } from '@/lib/config'
import ProductCard from './ProductCard'
import BlogPostListEmpty from './BlogPostListEmpty'
import { useGlobal } from '@/lib/global'
import CONFIG from '../config'
import { getListByPage } from '@/lib/utils'
import { useEffect, useRef, useState } from 'react'
import CONFIG from '../config'
import BlogPostListEmpty from './BlogPostListEmpty'
import ProductCard from './ProductCard'
/**
* 博客列表滚动分页
@@ -13,15 +13,22 @@ import { useEffect, useRef, useState } from 'react'
* @returns {JSX.Element}
* @constructor
*/
const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG.POST_LIST_SUMMARY, siteInfo }) => {
const postsPerPage = parseInt(siteConfig('POSTS_PER_PAGE'))
const BlogPostListScroll = ({
posts = [],
currentSearch,
showSummary = CONFIG.POST_LIST_SUMMARY,
siteInfo
}) => {
const { NOTION_CONFIG } = useGlobal()
const POSTS_PER_PAGE = siteConfig('POSTS_PER_PAGE', 12, NOTION_CONFIG)
const [page, updatePage] = useState(1)
const postsToShow = getListByPage(posts, page, postsPerPage)
const postsToShow = getListByPage(posts, page, POSTS_PER_PAGE)
let hasMore = false
if (posts) {
const totalCount = posts.length
hasMore = page * postsPerPage < totalCount
hasMore = page * POSTS_PER_PAGE < totalCount
}
const handleGetMore = () => {
@@ -33,7 +40,11 @@ const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG.PO
const scrollTrigger = () => {
requestAnimationFrame(() => {
const scrollS = window.scrollY + window.outerHeight
const clientHeight = targetRef ? (targetRef.current ? (targetRef.current.clientHeight) : 0) : 0
const clientHeight = targetRef
? targetRef.current
? targetRef.current.clientHeight
: 0
: 0
if (scrollS > clientHeight + 100) {
handleGetMore()
}
@@ -54,21 +65,32 @@ const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG.PO
if (!postsToShow || postsToShow.length === 0) {
return <BlogPostListEmpty currentSearch={currentSearch} />
} else {
return <div id='container' ref={targetRef} className='w-full'>
return (
<div id='container' ref={targetRef} className='w-full'>
{/* 文章列表 */}
<div className='space-y-6 px-2'>
{postsToShow.map(post => (
<ProductCard
key={post.id}
post={post}
showSummary={showSummary}
siteInfo={siteInfo}
/>
))}
</div>
{/* 文章列表 */}
<div className="space-y-6 px-2">
{postsToShow.map(post => (
<ProductCard key={post.id} post={post} showSummary={showSummary} siteInfo={siteInfo}/>
))}
<div>
<div
onClick={() => {
handleGetMore()
}}
className='w-full my-4 py-4 text-center cursor-pointer rounded-xl dark:text-gray-200'>
{' '}
{hasMore ? locale.COMMON.MORE : `${locale.COMMON.NO_MORE}`}{' '}
</div>
</div>
</div>
<div>
<div onClick={() => { handleGetMore() }}
className='w-full my-4 py-4 text-center cursor-pointer rounded-xl dark:text-gray-200'
> {hasMore ? locale.COMMON.MORE : `${locale.COMMON.NO_MORE}`} </div>
</div>
</div>
)
}
}