mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-30 07:26:45 +00:00
feature:
封装useGlobal组件,存放全局变量; 新增search页面,修复搜索页无法分页的bug
This commit is contained in:
@@ -7,16 +7,14 @@ import 'font-awesome/css/font-awesome.min.css'
|
||||
|
||||
import BLOG from '@/blog.config'
|
||||
import dynamic from 'next/dynamic'
|
||||
import { LocaleProvider } from '@/lib/locale'
|
||||
import { ThemeProvider } from '@/lib/theme'
|
||||
import { GlobalContextProvider } from '@/lib/global'
|
||||
|
||||
const Ackee = dynamic(() => import('@/components/Ackee'), { ssr: false })
|
||||
const Gtag = dynamic(() => import('@/components/Gtag'), { ssr: false })
|
||||
|
||||
const MyApp = ({ Component, pageProps }) => {
|
||||
return (
|
||||
<LocaleProvider>
|
||||
<ThemeProvider>
|
||||
<GlobalContextProvider>
|
||||
{BLOG.isProd && BLOG?.analytics?.provider === 'ackee' && (
|
||||
<Ackee
|
||||
ackeeServerUrl={BLOG.analytics.ackeeConfig.dataAckeeServer}
|
||||
@@ -25,8 +23,7 @@ const MyApp = ({ Component, pageProps }) => {
|
||||
)}
|
||||
{BLOG.isProd && BLOG?.analytics?.provider === 'ga' && <Gtag />}
|
||||
<Component {...pageProps} />
|
||||
</ThemeProvider>
|
||||
</LocaleProvider>
|
||||
</GlobalContextProvider>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ const BlogPost = ({ post, blockMap, tags, prev, next, posts }) => {
|
||||
const targetRef = useRef(null)
|
||||
const url = BLOG.link + useRouter().asPath
|
||||
|
||||
return <BaseLayout meta={meta} tags={tags} post={post} posts={posts}>
|
||||
return <BaseLayout meta={meta} tags={tags} totalPosts={post} posts={posts}>
|
||||
{/* 阅读进度条 */}
|
||||
<Progress targetRef={targetRef} />
|
||||
|
||||
@@ -61,8 +61,12 @@ const BlogPost = ({ post, blockMap, tags, prev, next, posts }) => {
|
||||
{post.title}
|
||||
</h1>
|
||||
|
||||
<h2 className='text-gray-500 my-5 dark:text-gray-400 animate__animated animate__fadeIn'>
|
||||
{post.summary}
|
||||
</h2>
|
||||
|
||||
{/* 文章信息 */}
|
||||
<div className='justify-between flex flex-wrap bg-gray-50 p-2 dark:bg-gray-700 dark:text-white'>
|
||||
<div className='justify-between flex flex-wrap bg-gray-50 p-2 dark:bg-gray-800 dark:text-white'>
|
||||
<div className='flex-nowrap flex'>
|
||||
|
||||
{post.slug !== 'about' && (<>
|
||||
|
||||
@@ -27,7 +27,7 @@ export async function getStaticProps () {
|
||||
|
||||
const Index = ({ posts, tags, meta }) => {
|
||||
return (
|
||||
<BaseLayout meta={meta} tags={tags} posts={posts}>
|
||||
<BaseLayout meta={meta} tags={tags} totalPosts={posts}>
|
||||
<div className='flex-grow bg-gray-200 dark:bg-black shadow-inner'>
|
||||
<TagsBar tags={tags} />
|
||||
<BlogPostListScroll posts={posts} tags={tags} />
|
||||
|
||||
57
pages/search.js
Normal file
57
pages/search.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import { getAllPosts, getAllTags } from '@/lib/notion'
|
||||
import BLOG from '@/blog.config'
|
||||
import BaseLayout from '@/layouts/BaseLayout'
|
||||
import TagsBar from '@/components/TagsBar'
|
||||
import BlogPostListScroll from '@/components/BlogPostListScroll'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
export async function getStaticProps () {
|
||||
let posts = await getAllPosts({ from: 'index' })
|
||||
posts = posts.filter(
|
||||
post => post.status[0] === 'Published' && post.type[0] === 'Post'
|
||||
)
|
||||
const tags = await getAllTags(posts)
|
||||
const meta = {
|
||||
title: `${BLOG.title} | ${BLOG.description} `,
|
||||
description: BLOG.description,
|
||||
type: 'website'
|
||||
}
|
||||
return {
|
||||
props: {
|
||||
posts,
|
||||
tags,
|
||||
meta
|
||||
},
|
||||
revalidate: 1
|
||||
}
|
||||
}
|
||||
|
||||
const Search = ({ posts, tags, meta }) => {
|
||||
// 处理查询过滤 支持标签、关键词过滤
|
||||
let filteredPosts = []
|
||||
const searchKey = getSearchKey()
|
||||
if (searchKey) {
|
||||
filteredPosts = posts.filter(post => {
|
||||
const tagContent = post.tags ? post.tags.join(' ') : ''
|
||||
const searchContent = post.title + post.summary + tagContent
|
||||
return searchContent.toLowerCase().includes(searchKey.toLowerCase())
|
||||
})
|
||||
}
|
||||
return (
|
||||
<BaseLayout meta={meta} tags={tags} totalPosts={posts} currentSearch={searchKey}>
|
||||
<div className='flex-grow bg-gray-200 dark:bg-black shadow-inner'>
|
||||
<TagsBar tags={tags} />
|
||||
<BlogPostListScroll posts={filteredPosts} tags={tags} />
|
||||
</div>
|
||||
</BaseLayout>
|
||||
)
|
||||
}
|
||||
|
||||
export function getSearchKey () {
|
||||
const router = useRouter()
|
||||
if (router.query && router.query.s) {
|
||||
return router.query.s
|
||||
}
|
||||
return null
|
||||
}
|
||||
export default Search
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getAllPosts, getAllTags } from '@/lib/notion'
|
||||
import BLOG from '@/blog.config'
|
||||
import TagsBar from '@/components/TagsBar'
|
||||
import BlogPostList from '@/components/BlogPostList'
|
||||
import BlogPostListPage from '@/components/BlogPostListPage'
|
||||
import BaseLayout from '@/layouts/BaseLayout'
|
||||
|
||||
export default function Tag ({ tags, posts, currentTag }) {
|
||||
@@ -13,7 +13,7 @@ export default function Tag ({ tags, posts, currentTag }) {
|
||||
return <BaseLayout meta={meta} tags={tags} currentTag={currentTag}>
|
||||
<div className='flex-grow'>
|
||||
<TagsBar tags={tags} currentTag={currentTag}/>
|
||||
<BlogPostList posts={posts} tags={tags}/>
|
||||
<BlogPostListPage posts={posts} tags={tags}/>
|
||||
</div>
|
||||
</BaseLayout>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user