diff --git a/pages/tag/index.js b/pages/tag/index.js index 042af0bc..93965586 100644 --- a/pages/tag/index.js +++ b/pages/tag/index.js @@ -27,7 +27,6 @@ const TagIndex = props => { export async function getStaticProps() { const from = 'tag-index-props' const props = await getGlobalNotionData({ from }) - console.log('获取所有标签', props) props.tags = getAllTags({ allPages: props.allPages, sliceCount: 0, tagOptions: props.tagOptions }) delete props.tagOptions return { diff --git a/themes/example/LayoutCategory.js b/themes/example/LayoutCategory.js index a9c99d90..6d819185 100644 --- a/themes/example/LayoutCategory.js +++ b/themes/example/LayoutCategory.js @@ -1,61 +1,10 @@ import BLOG from '@/blog.config' -import { useGlobal } from '@/lib/global' -import Link from 'next/link' -import { useState } from 'react' +import { BlogListPage } from './components/BlogListPage' +import { BlogListScroll } from './components/BlogListScroll' import LayoutBase from './LayoutBase' export const LayoutCategory = props => { - const { category, posts } = props - const { locale } = useGlobal() - - const [page, updatePage] = useState(1) - let hasMore = false - const postsToShow = posts - ? Object.assign(posts).slice(0, BLOG.POSTS_PER_PAGE * page) - : [] - - if (posts) { - const totalCount = posts.length - hasMore = page * BLOG.POSTS_PER_PAGE < totalCount - } - const handleGetMore = () => { - if (!hasMore) return - updatePage(page + 1) - } - return -
-
{category}
- - {postsToShow.map(p => ( - - ))} - -
- {' '} - {hasMore ? locale.COMMON.MORE : `${locale.COMMON.NO_MORE} 😰`}{' '} -
-
+ {BLOG.POST_LIST_STYLE === 'page' ? : }
} diff --git a/themes/example/LayoutCategoryIndex.js b/themes/example/LayoutCategoryIndex.js index 7690b316..28b98b6e 100644 --- a/themes/example/LayoutCategoryIndex.js +++ b/themes/example/LayoutCategoryIndex.js @@ -5,7 +5,6 @@ export const LayoutCategoryIndex = (props) => { const { categories } = props return -
{categories && categories.map(category => { return @@ -16,6 +15,5 @@ export const LayoutCategoryIndex = (props) => { })}
-
} diff --git a/themes/example/LayoutIndex.js b/themes/example/LayoutIndex.js index 7d6a17a6..17b77b4a 100644 --- a/themes/example/LayoutIndex.js +++ b/themes/example/LayoutIndex.js @@ -1,11 +1,11 @@ -import { BlogList } from './components/BlogList' +import { BlogListPage } from './components/BlogListPage' import LayoutBase from './LayoutBase' export const LayoutIndex = props => { return ( - + ) } diff --git a/themes/example/LayoutPage.js b/themes/example/LayoutPage.js index fc19035f..15355018 100644 --- a/themes/example/LayoutPage.js +++ b/themes/example/LayoutPage.js @@ -1,10 +1,10 @@ -import { BlogList } from './components/BlogList' +import { BlogListPage } from './components/BlogListPage' import LayoutBase from './LayoutBase' export const LayoutPage = props => { return ( - + ) } diff --git a/themes/example/LayoutTag.js b/themes/example/LayoutTag.js index f60653e3..06a6d778 100644 --- a/themes/example/LayoutTag.js +++ b/themes/example/LayoutTag.js @@ -1,59 +1,10 @@ import BLOG from '@/blog.config' -import { useGlobal } from '@/lib/global' -import Link from 'next/link' -import { useState } from 'react' +import { BlogListPage } from './components/BlogListPage' +import { BlogListScroll } from './components/BlogListScroll' import LayoutBase from './LayoutBase' export const LayoutTag = props => { - const { posts } = props - const { locale } = useGlobal() - - const [page, updatePage] = useState(1) - - let hasMore = false - const postsToShow = posts - ? Object.assign(posts).slice(0, BLOG.POSTS_PER_PAGE * page) - : [] - - if (posts) { - const totalCount = posts.length - hasMore = page * BLOG.POSTS_PER_PAGE < totalCount - } - const handleGetMore = () => { - if (!hasMore) return - updatePage(page + 1) - } - - return - {postsToShow.map(p => ( -
-

- - {p.title} - -

- -
- by {BLOG.AUTHOR} on {p.date?.start_date || p.createdTime} - | - {p.category} - | - {/* 2 Comments */} -
- -

- {p.summary} -

-
- ))} - -
- {' '} - {hasMore ? locale.COMMON.MORE : `${locale.COMMON.NO_MORE} 😰`}{' '} -
- + return + {BLOG.POST_LIST_STYLE === 'page' ? : } } diff --git a/themes/example/components/BlogList.js b/themes/example/components/BlogListPage.js similarity index 76% rename from themes/example/components/BlogList.js rename to themes/example/components/BlogListPage.js index 1a45d6f7..5eb89ece 100644 --- a/themes/example/components/BlogList.js +++ b/themes/example/components/BlogListPage.js @@ -4,20 +4,17 @@ import { useGlobal } from '@/lib/global' import { useRouter } from 'next/router' import Link from 'next/link' -export const BlogList = (props) => { - const { page, posts, postCount } = props - +export const BlogListPage = props => { + const { page = 1, posts, postCount } = props const { locale } = useGlobal() const router = useRouter() const totalPage = Math.ceil(postCount / BLOG.POSTS_PER_PAGE) - - const showNext = - page < totalPage && - posts.length === BLOG.POSTS_PER_PAGE && - posts.length < postCount - const currentPage = +page + const showPrev = currentPage > 1 + const showNext = page < totalPage + const pagePrefix = router.asPath.replace(/\/page\/[1-9]\d*/, '').replace(/\/$/, '') + return
{posts.map(p => ( @@ -51,10 +48,10 @@ export const BlogList = (props) => { ))}
- - 1 ? 'bg-black ' : 'bg-gray pointer-events-none '} text-white no-underline py-2 px-3 rounded`}>{locale.PAGINATION.PREV} + + {locale.PAGINATION.PREV} - + {locale.PAGINATION.NEXT}
diff --git a/themes/example/components/BlogListScroll.js b/themes/example/components/BlogListScroll.js new file mode 100644 index 00000000..0492eb14 --- /dev/null +++ b/themes/example/components/BlogListScroll.js @@ -0,0 +1,58 @@ +import BLOG from '@/blog.config' +import { useGlobal } from '@/lib/global' +import Link from 'next/link' +import { useState } from 'react' + +export const BlogListScroll = props => { + const { posts } = props + const { locale } = useGlobal() + + const [page, updatePage] = useState(1) + + let hasMore = false + const postsToShow = posts + ? Object.assign(posts).slice(0, BLOG.POSTS_PER_PAGE * page) + : [] + + if (posts) { + const totalCount = posts.length + hasMore = page * BLOG.POSTS_PER_PAGE < totalCount + } + const handleGetMore = () => { + if (!hasMore) return + updatePage(page + 1) + } + + return
+ {postsToShow.map(p => ( + + ))} + +
+ {' '} + {hasMore ? locale.COMMON.MORE : `${locale.COMMON.NO_MORE} 😰`}{' '} +
+ +
+}