+
{slotLeft}
- {router.pathname !== '/search' && }
+
{/* 所有文章列表 */}
-
+
-
+
{slotTop}
{onLoading ? LoadingCover : children}
@@ -81,15 +85,20 @@ const LayoutBase = props => {
{/* 右侧侧推拉抽屉 */}
-
+
diff --git a/themes/gitbook/LayoutSearch.js b/themes/gitbook/LayoutSearch.js
index 1aaf3d20..eaecbd84 100644
--- a/themes/gitbook/LayoutSearch.js
+++ b/themes/gitbook/LayoutSearch.js
@@ -30,7 +30,7 @@ export const LayoutSearch = (props) => {
}
},
100)
- })
+ }, [currentSearch])
return
- {slotRight}
-
-
diff --git a/themes/gitbook/LayoutIndex.js b/themes/gitbook/LayoutIndex.js
index 6071f9fc..50c89f12 100644
--- a/themes/gitbook/LayoutIndex.js
+++ b/themes/gitbook/LayoutIndex.js
@@ -1,6 +1,5 @@
import LayoutBase from './LayoutBase'
import Announcement from './components/Announcement'
-import ArticleInfo from './components/ArticleInfo'
export const LayoutIndex = (props) => {
return
-
- {CONFIG_MEDIUM.WIDGET_REVOLVER_MAPS === 'true' && }
+
+
+
+
+
+ {slotRight}
+ {router.route === '/' && <>
+
+ {CONFIG_MEDIUM.WIDGET_REVOLVER_MAPS === 'true' && }
+
+ >}
-
diff --git a/themes/gitbook/LayoutSlug.js b/themes/gitbook/LayoutSlug.js
index 78b0f5b2..f3b7d058 100644
--- a/themes/gitbook/LayoutSlug.js
+++ b/themes/gitbook/LayoutSlug.js
@@ -1,11 +1,6 @@
import LayoutBase from './LayoutBase'
-import { useGlobal } from '@/lib/global'
import React from 'react'
-import Catalog from './components/Catalog'
import { ArticleLock } from './components/ArticleLock'
-import formatDate from '@/lib/formatDate'
-import BLOG from '@/blog.config'
-import Link from 'next/link'
import NotionPage from '@/components/NotionPage'
import CONFIG_MEDIUM from './config_medium'
import Comment from '@/components/Comment'
@@ -16,22 +11,14 @@ import TagItemMini from './components/TagItemMini'
import ShareBar from '@/components/ShareBar'
export const LayoutSlug = (props) => {
- const { post, prev, next, siteInfo, lock, validPassword } = props
- const { locale } = useGlobal()
-
- const date = formatDate(
- post?.date?.start_date || post?.createdTime,
- locale.LOCALE
- )
-
- const slotRight = post?.toc && post?.toc?.length > 3 &&
- console.log(slotRight, post, 'jhhh')
+ const { post, prev, next, lock, validPassword } = props
if (!post) {
return
}
+
return (
-
+
{/* 文章锁 */}
{lock && }
@@ -40,30 +27,8 @@ export const LayoutSlug = (props) => {
{/* title */}
-
-
{/* Notion文章主体 */}
-
+
{post && ( )}
@@ -73,13 +38,13 @@ export const LayoutSlug = (props) => {
{/* 文章分类和标签信息 */}
}
+ {post?.type === 'Post' && }
diff --git a/themes/gitbook/components/BlogPostCard.js b/themes/gitbook/components/BlogPostCard.js
index fd277508..299bc7f3 100644
--- a/themes/gitbook/components/BlogPostCard.js
+++ b/themes/gitbook/components/BlogPostCard.js
@@ -1,27 +1,25 @@
import BLOG from '@/blog.config'
import Link from 'next/link'
+import { useRouter } from 'next/router'
import React from 'react'
-const BlogPostCard = ({ post, showSummary }) => {
+const BlogPostCard = ({ post }) => {
+ const router = useRouter()
+ const currentSelected = router.asPath.split('?')[0] === '/' + post.slug
return (
-
{post?.title}
- {/* meta */} -
- {date}
- |
- {post.lastEditedTime}
-
-
-
-
-
-
- {/* eslint-disable-next-line @next/next/no-img-element */}
-
-
-
-
-
- {BLOG.AUTHOR}
-
-
- {CONFIG_MEDIUM.POST_DETAIL_CATEGORY && post.category && }
+ {CONFIG_MEDIUM.POST_DETAIL_CATEGORY && post?.category && }
- {post.type === 'Post' &&
{CONFIG_MEDIUM.POST_DETAIL_TAG && post?.tagItems?.map(tag => )}
-
+
)
diff --git a/themes/gitbook/components/BlogPostListScroll.js b/themes/gitbook/components/BlogPostListScroll.js
index 2212d51e..ae2f0951 100644
--- a/themes/gitbook/components/BlogPostListScroll.js
+++ b/themes/gitbook/components/BlogPostListScroll.js
@@ -1,9 +1,6 @@
-import BLOG from '@/blog.config'
import BlogPostCard from './BlogPostCard'
import BlogPostListEmpty from './BlogPostListEmpty'
-import throttle from 'lodash.throttle'
-import React, { useCallback, useEffect, useRef, useState } from 'react'
-import { useRouter } from 'next/router'
+import React, { useRef } from 'react'
/**
* 博客列表滚动分页
@@ -13,85 +10,19 @@ import { useRouter } from 'next/router'
* @constructor
*/
const BlogPostListScroll = ({ posts = [], currentSearch }) => {
- const postsPerPage = BLOG.POSTS_PER_PAGE
- const [page, updatePage] = useState(1)
- let filteredPosts = Object.assign(posts)
- const router = useRouter()
- const searchKey = getSearchKey(router)
- 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())
- })
- }
- const postsToShow = getPostByPage(page, filteredPosts, postsPerPage)
-
- let hasMore = false
- if (filteredPosts) {
- const totalCount = filteredPosts.length
- hasMore = page * postsPerPage < totalCount
- }
-
- const handleGetMore = () => {
- if (!hasMore) return
- updatePage(page + 1)
- }
-
- // 监听滚动自动分页加载
- const scrollTrigger = useCallback(throttle(() => {
- const scrollS = window.scrollY + window.outerHeight
- const clientHeight = targetRef ? (targetRef.current ? (targetRef.current.clientHeight) : 0) : 0
- if (scrollS > clientHeight + 100) {
- handleGetMore()
- }
- }, 500))
-
- // 监听滚动
- useEffect(() => {
- window.addEventListener('scroll', scrollTrigger)
- return () => {
- window.removeEventListener('scroll', scrollTrigger)
- }
- })
-
const targetRef = useRef(null)
+ const filteredPosts = Object.assign(posts)
- if (!postsToShow || postsToShow.length === 0) {
+ if (!filteredPosts || filteredPosts.length === 0) {
return
} else {
return
+ ))}
+
}
}
-/**
- * 获取从第1页到指定页码的文章
- * @param page 第几页
- * @param totalPosts 所有文章
- * @param postsPerPage 每页文章数量
- * @returns {*}
- */
-const getPostByPage = function (page, totalPosts, postsPerPage) {
- return totalPosts.slice(
- 0,
- postsPerPage * page
- )
-}
-
-function getSearchKey(router) {
- if (router.query && router.query.s) {
- return router.query.s
- }
- return null
-}
-
export default BlogPostListScroll
diff --git a/themes/gitbook/components/Catalog.js b/themes/gitbook/components/Catalog.js
index c9592dd2..a8f01fcf 100644
--- a/themes/gitbook/components/Catalog.js
+++ b/themes/gitbook/components/Catalog.js
@@ -1,7 +1,7 @@
-import { useCallback, useEffect, useRef, useState } from 'react'
+import { useCallback, useEffect, useState } from 'react'
import throttle from 'lodash.throttle'
import { uuidToId } from 'notion-utils'
-import Progress from './Progress'
+import { isBrowser } from '@/lib/utils'
/**
* 目录导航组件
@@ -9,11 +9,9 @@ import Progress from './Progress'
* @returns {JSX.Element}
* @constructor
*/
-const Catalog = ({ toc }) => {
+const Catalog = ({ post }) => {
const tocIds = []
-
- // 目录自动滚动
- const tRef = useRef(null)
+ const toc = post?.toc
// 同步选中目录事件
const [activeSection, setActiveSection] = useState(null)
@@ -24,7 +22,7 @@ const Catalog = ({ toc }) => {
return () => {
window.removeEventListener('scroll', actionSectionScrollSpy)
}
- }, [])
+ }, [post])
const throttleMs = 200
const actionSectionScrollSpy = useCallback(throttle(() => {
@@ -51,19 +49,18 @@ const Catalog = ({ toc }) => {
}
setActiveSection(currentSectionId)
const index = tocIds.indexOf(currentSectionId) || 0
- tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' })
+ if (isBrowser()) {
+ document?.getElementById('toc-wrapper')?.scrollTo({ top: 28 * index, behavior: 'smooth' })
+ }
}, throttleMs))
// 无目录就直接返回空
if (!toc || toc.length < 1) {
- return <>>
+ return null
}
- return
{post.category} - {post.title}
-
-
- {/* 文章列表 */}
-
+ {/* 文章列表 */}
+ {filteredPosts?.map(post => (
+
- {postsToShow?.map(post => (
-
- ))}
-
-
-
-
>} + + + + + +
+ changeShow(true)} onMouseOut={() => changeShow(false)} >
{hasSubMenu &&
-
-
-
-
+ return <>
+
-
+ >
}
export default Catalog
diff --git a/themes/gitbook/components/Footer.js b/themes/gitbook/components/Footer.js
index cde8885e..744f9e61 100644
--- a/themes/gitbook/components/Footer.js
+++ b/themes/gitbook/components/Footer.js
@@ -5,7 +5,7 @@ import DarkModeButton from '@/components/DarkModeButton'
const Footer = ({ title }) => {
const d = new Date()
const currentYear = d.getFullYear()
- const copyrightDate = (function() {
+ const copyrightDate = (function () {
if (Number.isInteger(BLOG.SINCE) && BLOG.SINCE < currentYear) {
return BLOG.SINCE + '-' + currentYear
}
@@ -13,22 +13,26 @@ const Footer = ({ title }) => {
})()
return (
-
+ {BLOG.BEI_AN && <> {BLOG.BEI_AN}>} + + + + + +
+
{title}
+ + ) } diff --git a/themes/gitbook/components/MenuItemDrop.js b/themes/gitbook/components/MenuItemDrop.js index 92cd9142..3ef482b5 100644 --- a/themes/gitbook/components/MenuItemDrop.js +++ b/themes/gitbook/components/MenuItemDrop.js @@ -17,7 +17,7 @@ export const MenuItemDrop = ({ link }) => { return
{link?.icon && } {link?.name}
@@ -27,7 +27,7 @@ export const MenuItemDrop = ({ link }) => {
}
{!hasSubMenu &&
-
{link?.icon && } {link?.name}
diff --git a/themes/gitbook/components/RevolverMaps.js b/themes/gitbook/components/RevolverMaps.js
index d839d85d..c6eb6252 100644
--- a/themes/gitbook/components/RevolverMaps.js
+++ b/themes/gitbook/components/RevolverMaps.js
@@ -7,7 +7,7 @@ export default function RevolverMaps () {
initRevolverMaps()
changeLoad(true)
}
- })
+ }, [])
return
}
diff --git a/themes/gitbook/components/SearchInput.js b/themes/gitbook/components/SearchInput.js
index f6c84d9c..6828d111 100644
--- a/themes/gitbook/components/SearchInput.js
+++ b/themes/gitbook/components/SearchInput.js
@@ -1,11 +1,11 @@
-import { useRouter } from 'next/router'
import { useImperativeHandle, useRef, useState } from 'react'
+import { useMediumGlobal } from '../LayoutBase'
let lock = false
-const SearchInput = ({ currentTag, currentSearch, cRef, className }) => {
- const [onLoading, setLoadingState] = useState(false)
- const router = useRouter()
+const SearchInput = ({ currentSearch, cRef, className }) => {
const searchInputRef = useRef()
+ const { setFilterPosts, allNavPages } = useMediumGlobal()
+
useImperativeHandle(cRef, () => {
return {
focus: () => {
@@ -15,15 +15,43 @@ const SearchInput = ({ currentTag, currentSearch, cRef, className }) => {
})
const handleSearch = () => {
- const key = searchInputRef.current.value
-
- if (key && key !== '') {
- setLoadingState(true)
- location.href = '/search/' + key
+ let keyword = searchInputRef.current.value
+ const filterPosts = []
+ if (keyword) {
+ keyword = keyword.trim()
} else {
- router.push({ pathname: '/' }).then(r => {
- })
+ setFilterPosts(allNavPages)
}
+ for (const post of allNavPages) {
+ const tagContent = post.tags && Array.isArray(post.tags) ? post.tags.join(' ') : ''
+ const categoryContent = post.category && Array.isArray(post.category) ? post.category.join(' ') : ''
+ const articleInfo = post.title + post.summary + tagContent + categoryContent
+ let hit = articleInfo.toLowerCase().indexOf(keyword) > -1
+ const indexContent = [post.summary]
+ // console.log('全文搜索缓存', cacheKey, page != null)
+ post.results = []
+ let hitCount = 0
+ for (const i in indexContent) {
+ const c = indexContent[i]
+ if (!c) {
+ continue
+ }
+ const index = c.toLowerCase().indexOf(keyword.toLowerCase())
+ if (index > -1) {
+ hit = true
+ hitCount += 1
+ post.results.push(c)
+ } else {
+ if ((post.results.length - 1) / hitCount < 3 || i === 0) {
+ post.results.push(c)
+ }
+ }
+ }
+ if (hit) {
+ filterPosts.push(post)
+ }
+ }
+ setFilterPosts(filterPosts)
}
const handleKeyUp = (e) => {
if (e.keyCode === 13) { // 回车
@@ -72,7 +100,7 @@ const SearchInput = ({ currentTag, currentSearch, cRef, className }) => {
-
+
{(showClean &&
diff --git a/themes/gitbook/components/TopNavBar.js b/themes/gitbook/components/TopNavBar.js
index 8b07a5de..e5081945 100644
--- a/themes/gitbook/components/TopNavBar.js
+++ b/themes/gitbook/components/TopNavBar.js
@@ -6,6 +6,7 @@ import { useGlobal } from '@/lib/global'
import CONFIG_MEDIUM from '../config_medium'
import BLOG from '@/blog.config'
import { MenuItemDrop } from './MenuItemDrop'
+import DarkModeButton from '@/components/DarkModeButton'
/**
* 顶部导航栏 + 菜单
@@ -67,6 +68,7 @@ export default function TopNavBar(props) {
{/* 桌面端顶部菜单 */}
{links && links?.map(link => )}
+