From bfcca16a86d4e86e1546bb384d8c22439aacf784 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Mon, 19 Feb 2024 11:51:39 +0800 Subject: [PATCH 1/3] =?UTF-8?q?heo=20=E5=B9=BF=E5=91=8A=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- next.config.js | 17 +++++++---------- themes/heo/components/SideRight.js | 2 ++ themes/heo/index.js | 8 ++++---- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/next.config.js b/next.config.js index 732303bf..fd0130ec 100644 --- a/next.config.js +++ b/next.config.js @@ -8,7 +8,7 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({ }) /** - * 扫描指定目录下的文件夹名,用于获取当前有几个主题 + * 扫描指定目录下的文件夹名,用于获取所有主题 * @param {*} directory * @returns */ @@ -16,16 +16,13 @@ function scanSubdirectories(directory) { const subdirectories = [] fs.readdirSync(directory).forEach(file => { - // 这段代码会将landing排除在可选主题中 + const fullPath = path.join(directory, file) + const stats = fs.statSync(fullPath) + if (stats.isDirectory()) { + subdirectories.push(file) + } - // const fullPath = path.join(directory, file) - // const stats = fs.statSync(fullPath) - // landing主题默认隐藏掉,一般网站不会用到 - // if (stats.isDirectory() && file !== 'landing') { - // subdirectories.push(file) - // } - - subdirectories.push(file) + // subdirectories.push(file) }) return subdirectories diff --git a/themes/heo/components/SideRight.js b/themes/heo/components/SideRight.js index ec1d4fb7..775b9b76 100644 --- a/themes/heo/components/SideRight.js +++ b/themes/heo/components/SideRight.js @@ -38,6 +38,8 @@ export default function SideRight(props) {
+ + {/* 文章页显示目录 */} {post && post.toc && post.toc.length > 0 && ( diff --git a/themes/heo/index.js b/themes/heo/index.js index 54d328ed..239f30dc 100644 --- a/themes/heo/index.js +++ b/themes/heo/index.js @@ -310,7 +310,10 @@ const LayoutSlug = props => { ? null :

- + {/* 评论区上方广告 */} +
+ +
{/* 评论互动 */}
@@ -318,9 +321,6 @@ const LayoutSlug = props => { {locale.COMMON.COMMENTS}
-
- -
}
From 140c15727ef4888eca7742b6b571e36941067b85 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Mon, 19 Feb 2024 17:43:15 +0800 Subject: [PATCH 2/3] log --- lib/notion/getNotionData.js | 2 +- lib/notion/getPostBlocks.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 80466b9e..d3a2b2de 100755 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -106,7 +106,7 @@ export async function getNotionPageData({ pageId, from }) { const cacheKey = 'page_block_' + pageId const data = await getDataFromCache(cacheKey) if (data && data.pageIds?.length > 0) { - console.log('[缓存]:', `from:${from}`, `root-page-id:${pageId}`) + console.log('[API<<--缓存]', `from:${from}`, `root-page-id:${pageId}`) return data } const db = await getDataBaseInfoByNotionAPI({ pageId, from }) diff --git a/lib/notion/getPostBlocks.js b/lib/notion/getPostBlocks.js index 69888b5d..8999cae2 100644 --- a/lib/notion/getPostBlocks.js +++ b/lib/notion/getPostBlocks.js @@ -14,7 +14,7 @@ export async function getPostBlocks(id, from, slice) { const cacheKey = 'page_block_' + id let pageBlock = await getDataFromCache(cacheKey) if (pageBlock) { - console.log('[缓存]:', `from:${from}`, cacheKey) + console.log('[API<<--缓存]', `from:${from}`, cacheKey) return filterPostBlocks(id, pageBlock, slice) } @@ -31,7 +31,7 @@ export async function getSingleBlock(id, from) { const cacheKey = 'single_block_' + id let pageBlock = await getDataFromCache(cacheKey) if (pageBlock) { - console.log('[缓存]:', `from:${from}`, cacheKey) + console.log('[API<<--缓存]', `from:${from}`, cacheKey) return pageBlock } From 29407c1b0d65fc5b3741979dbc5790a78c4316b2 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Wed, 21 Feb 2024 13:49:52 +0800 Subject: [PATCH 3/3] =?UTF-8?q?gitbook=20=E9=80=82=E9=85=8Dalgolia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/gitbook/components/NavPostList.js | 2 +- themes/gitbook/components/SearchInput.js | 42 ++++++++++++++---------- themes/gitbook/components/TopNavBar.js | 2 +- themes/gitbook/index.js | 8 +++-- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/themes/gitbook/components/NavPostList.js b/themes/gitbook/components/NavPostList.js index 6ad7fd94..6fbf92b5 100644 --- a/themes/gitbook/components/NavPostList.js +++ b/themes/gitbook/components/NavPostList.js @@ -20,7 +20,7 @@ const NavPostList = (props) => { let existingGroup = null // 开启自动分组排序 - if (JSON.parse(siteConfig('GITBOOK_AUTO_SORT', true, CONFIG))) { + if (siteConfig('GITBOOK_AUTO_SORT', true, CONFIG)) { existingGroup = groups.find(group => group.category === categoryName) // 搜索同名的最后一个分组 } else { existingGroup = groups[groups.length - 1] // 获取最后一个分组 diff --git a/themes/gitbook/components/SearchInput.js b/themes/gitbook/components/SearchInput.js index bad985da..cab041fe 100644 --- a/themes/gitbook/components/SearchInput.js +++ b/themes/gitbook/components/SearchInput.js @@ -1,11 +1,15 @@ import { useImperativeHandle, useRef, useState } from 'react' import { deepClone } from '@/lib/utils' import { useGitBookGlobal } from '@/themes/gitbook' +import { siteConfig } from '@/lib/config' let lock = false +/** + * 搜索栏 + */ const SearchInput = ({ currentSearch, cRef, className }) => { const searchInputRef = useRef() - const { setFilteredNavPages, allNavPages } = useGitBookGlobal() + const { searchModal, setFilteredNavPages, allNavPages } = useGitBookGlobal() useImperativeHandle(cRef, () => { return { @@ -16,6 +20,10 @@ const SearchInput = ({ currentSearch, cRef, className }) => { }) const handleSearch = () => { + // 使用Algolia + if (siteConfig('ALGOLIA_APP_ID')) { + searchModal?.current?.openSearch() + } let keyword = searchInputRef.current.value if (keyword) { keyword = keyword.trim() @@ -23,20 +31,7 @@ const SearchInput = ({ currentSearch, cRef, className }) => { setFilteredNavPages(allNavPages) } const filterAllNavPages = deepClone(allNavPages) - // for (const filterGroup of filterAllNavPages) { - // for (let i = filterGroup.items.length - 1; i >= 0; i--) { - // const post = filterGroup.items[i] - // const articleInfo = post.title + '' - // const hit = articleInfo.toLowerCase().indexOf(keyword.toLowerCase()) > -1 - // if (!hit) { - // // 删除 - // filterGroup.items.splice(i, 1) - // } - // } - // if (filterGroup.items && filterGroup.items.length > 0) { - // filterPosts.push(filterGroup) - // } - // } + for (let i = filterAllNavPages.length - 1; i >= 0; i--) { const post = filterAllNavPages[i] const articleInfo = post.title + '' @@ -56,6 +51,12 @@ const SearchInput = ({ currentSearch, cRef, className }) => { * @param {*} e */ const handleKeyUp = (e) => { + // 使用Algolia + if (siteConfig('ALGOLIA_APP_ID')) { + searchModal?.current?.openSearch() + return + } + if (e.keyCode === 13) { // 回车 handleSearch(searchInputRef.current.value) } else if (e.keyCode === 27) { // ESC @@ -63,6 +64,13 @@ const SearchInput = ({ currentSearch, cRef, className }) => { } } + const handleFocus = () => { + // 使用Algolia + if (siteConfig('ALGOLIA_APP_ID')) { + searchModal?.current?.openSearch() + } + } + /** * 清理搜索 */ @@ -77,7 +85,6 @@ const SearchInput = ({ currentSearch, cRef, className }) => { return } searchInputRef.current.value = val - if (val) { setShowClean(true) } else { @@ -97,6 +104,7 @@ const SearchInput = ({ currentSearch, cRef, className }) => { ref={searchInputRef} type='text' className={`${className} outline-none w-full text-sm pl-2 transition focus:shadow-lg font-light leading-10 text-black bg-gray-100 dark:bg-gray-900 dark:text-white`} + onFocus={handleFocus} onKeyUp={handleKeyUp} onCompositionStart={lockSearchInput} onCompositionUpdate={lockSearchInput} @@ -111,7 +119,7 @@ const SearchInput = ({ currentSearch, cRef, className }) => { {(showClean && -
+
)} diff --git a/themes/gitbook/components/TopNavBar.js b/themes/gitbook/components/TopNavBar.js index c2257fb5..b01c26cc 100644 --- a/themes/gitbook/components/TopNavBar.js +++ b/themes/gitbook/components/TopNavBar.js @@ -39,7 +39,7 @@ export default function TopNavBar(props) { } return ( -
+
{/* 移动端折叠菜单 */} diff --git a/themes/gitbook/index.js b/themes/gitbook/index.js index cd4f2207..d4bb22a1 100644 --- a/themes/gitbook/index.js +++ b/themes/gitbook/index.js @@ -2,7 +2,7 @@ import CONFIG from './config' import { useRouter } from 'next/router' -import { useEffect, useState, createContext, useContext } from 'react' +import { useEffect, useState, createContext, useContext, useRef } from 'react' import { isBrowser } from '@/lib/utils' import Footer from './components/Footer' import InfoCard from './components/InfoCard' @@ -34,6 +34,7 @@ import Link from 'next/link' import dynamic from 'next/dynamic' import { siteConfig } from '@/lib/config' import NotionIcon from '@/components/NotionIcon' +import AlgoliaSearchModal from '@/components/AlgoliaSearchModal' const WWAds = dynamic(() => import('@/components/WWAds'), { ssr: false }) // 主题全局变量 @@ -55,16 +56,19 @@ const LayoutBase = (props) => { const [filteredNavPages, setFilteredNavPages] = useState(allNavPages) const showTocButton = post?.toc?.length > 1 + const searchModal = useRef(null) useEffect(() => { setFilteredNavPages(allNavPages) }, [post]) return ( - +