diff --git a/pages/search/[keyword].js b/pages/search/[keyword].js index 3f6517bc..4bc6166e 100644 --- a/pages/search/[keyword].js +++ b/pages/search/[keyword].js @@ -4,6 +4,11 @@ import BLOG from '@/blog.config' import { useGlobal } from '@/lib/global' import { getDataFromCache } from '@/lib/cache/cache_manager' +/** + * 服务端搜索 + * @param {*} param0 + * @returns + */ export async function getServerSideProps ({ params: { keyword } }) { const { allPosts, diff --git a/pages/search/index.js b/pages/search/index.js index ef7cae89..fb1ffc89 100644 --- a/pages/search/index.js +++ b/pages/search/index.js @@ -4,6 +4,9 @@ import BLOG from '@/blog.config' import { useGlobal } from '@/lib/global' import { useRouter } from 'next/router' +/** + * 浏览器前端搜索 + */ export async function getStaticProps () { const { allPosts, diff --git a/themes/Hexo/LayoutSearch.js b/themes/Hexo/LayoutSearch.js index 3b26ad57..c9ffc4b3 100644 --- a/themes/Hexo/LayoutSearch.js +++ b/themes/Hexo/LayoutSearch.js @@ -1,9 +1,26 @@ +import { useRouter } from 'next/router' +import { useEffect } from 'react' import BlogPostListPage from './components/BlogPostListPage' import LayoutBase from './LayoutBase' export const LayoutSearch = (props) => { - return - + const { keyword } = props + const router = useRouter() + const currentSearch = keyword || router?.query?.s + useEffect(() => { + setTimeout(() => { + const container = document.getElementById('container') + if (container && container.innerHTML) { + const re = new RegExp(`${currentSearch}`, 'gim') + container.innerHTML = container.innerHTML.replace(re, `${currentSearch}`) + } + }, + 100) + }) + return +
+ +
} diff --git a/themes/Hexo/components/SideRight.js b/themes/Hexo/components/SideRight.js index 423481f6..3aafeb80 100644 --- a/themes/Hexo/components/SideRight.js +++ b/themes/Hexo/components/SideRight.js @@ -45,7 +45,7 @@ export default function SideRight (props) { - +