[删除旧分页page.js]保留滚动分页;
修复搜索页不重置bug;
This commit is contained in:
tangly1024
2021-11-04 10:11:03 +08:00
parent 5a2c1581b5
commit 8f9d3c45e7
4 changed files with 8 additions and 61 deletions

View File

@@ -1,6 +1,6 @@
import React, { useState } from 'react'
import { useLocale } from '@/lib/locale'
import Router, { useRouter } from 'next/router'
import { useRouter } from 'next/router'
const SearchInput = ({ currentTag }) => {
const locale = useLocale()
@@ -8,12 +8,12 @@ const SearchInput = ({ currentTag }) => {
const [searchValue, setSearchValue] = useState('')
const handleSearch = () => {
if (searchValue && searchValue !== '') {
Router.push({ pathname: '/page/1', query: { s: searchValue } }).then(r => {
console.log(r)
router.push({ pathname: '/', query: { s: searchValue } }).then(r => {
router.reload()
})
} else {
Router.push({ pathname: '/' }).then(r => {
console.log(r)
router.push({ pathname: '/' }).then(r => {
router.reload()
})
}
}

View File

@@ -43,7 +43,7 @@ const BlogPost = ({ post, blockMap, tags, prev, next, posts }) => {
{/* 阅读进度条 */}
<Progress targetRef={targetRef} />
<div id='article-wrapper' ref={targetRef} className='flex-grow bg-gray-200 dark:bg-black'>
<div id='article-wrapper' ref={targetRef} className='flex-grow bg-gray-200 dark:bg-black shadow-inner'>
{/* 中央区域 wrapper */}
<header
className='hover:shadow-2xl duration-200 mx-auto max-w-5xl mt-16 lg:mt-32 md:flex-shrink-0 animate__fadeIn animate__animated'>
@@ -55,7 +55,7 @@ const BlogPost = ({ post, blockMap, tags, prev, next, posts }) => {
</header>
<article
className='w-screen md:w-full overflow-x-auto md:px-10 px-5 py-10 max-w-5xl mx-auto dark:border-gray-700 bg-white dark:bg-gray-700'>
className='shadow mb-20 w-screen md:w-full overflow-x-auto md:px-10 px-5 py-10 max-w-5xl mx-auto dark:border-gray-700 bg-white dark:bg-gray-700'>
{/* 文章标题 */}
<h1 className='font-bold text-4xl text-black my-5 dark:text-white animate__animated animate__fadeIn'>
{post.title}

View File

@@ -28,7 +28,7 @@ export async function getStaticProps () {
const Index = ({ posts, tags, meta }) => {
return (
<BaseLayout meta={meta} tags={tags} posts={posts}>
<div className='flex-grow bg-gray-200 dark:bg-black'>
<div className='flex-grow bg-gray-200 dark:bg-black shadow-inner'>
<TagsBar tags={tags} />
<BlogPostListScroll posts={posts} tags={tags} />
</div>

View File

@@ -1,53 +0,0 @@
import { getAllPosts, getAllTags } from '@/lib/notion'
import BLOG from '@/blog.config'
import BaseLayout from '@/layouts/BaseLayout'
import TagsBar from '@/components/TagsBar'
import BlogPostList from '@/components/BlogPostList'
const Page = ({ posts, tags, page }) => {
const meta = {
title: `${BLOG.title} | 博客列表`,
description: BLOG.description,
type: 'website'
}
return <BaseLayout meta={meta} tags={tags}>
<div className='flex-grow'>
<TagsBar tags={tags} />
<BlogPostList posts={posts} tags={tags} page={page} />
</div>
</BaseLayout>
}
export async function getStaticPaths () {
let posts = await getAllPosts({ from: 'page-path' })
posts = posts.filter(
post => post.status[0] === 'Published' && post.type[0] === 'Post'
)
const totalPosts = posts.length
const totalPages = Math.ceil(totalPosts / BLOG.postsPerPage)
return {
paths: Array.from({ length: totalPages - 1 }, (_, i) => ({
params: { page: '' + (i + 1) }
})),
fallback: true
}
}
export async function getStaticProps (context) {
const { page } = context.params // Get Current Page No.
let posts = await getAllPosts({ from: 'page-props' })
posts = posts.filter(
post => post.status[0] === 'Published' && post.type[0] === 'Post'
)
const tags = await getAllTags(posts)
return {
props: {
tags,
posts,
page
},
revalidate: 1
}
}
export default Page