diff --git a/lib/db/getSiteData.js b/lib/db/getSiteData.js index cefc25f0..302efccf 100755 --- a/lib/db/getSiteData.js +++ b/lib/db/getSiteData.js @@ -63,7 +63,7 @@ export async function getSiteDataByPageId({ pageId, from }) { // 获取NOTION原始数据,此接支持mem缓存。 const pageRecordMap = await getPage(pageId, from) // 将Notion数据按规则转成站点数据 - const data = await converNotionToSiteDate(pageId, from, pageRecordMap) + const data = await converNotionToSiteDate(pageId, from, deepClone(pageRecordMap)) return data } diff --git a/themes/starter/components/SearchInput.js b/themes/starter/components/SearchInput.js new file mode 100644 index 00000000..1baf29e8 --- /dev/null +++ b/themes/starter/components/SearchInput.js @@ -0,0 +1,107 @@ +import { useGlobal } from '@/lib/global' +import { useRouter } from 'next/router' +import { useImperativeHandle, useRef, useState } from 'react' + +let lock = false + +/** + * 搜索输入框 + * @param {*} param0 + * @returns + */ +const SearchInput = ({ currentTag, keyword, cRef }) => { + const { locale } = useGlobal() + const router = useRouter() + const searchInputRef = useRef(null) + useImperativeHandle(cRef, () => { + return { + focus: () => { + searchInputRef?.current?.focus() + } + } + }) + const handleSearch = () => { + const key = searchInputRef.current.value + if (key && key !== '') { + router.push({ pathname: '/search/' + key }).then(r => {}) + } else { + router.push({ pathname: '/' }).then(r => {}) + } + } + const handleKeyUp = e => { + if (e.keyCode === 13) { + // 回车 + handleSearch(searchInputRef.current.value) + } else if (e.keyCode === 27) { + // ESC + cleanSearch() + } + } + const cleanSearch = () => { + searchInputRef.current.value = '' + setShowClean(false) + } + function lockSearchInput() { + lock = true + } + + function unLockSearchInput() { + lock = false + } + const [showClean, setShowClean] = useState(false) + const updateSearchKey = val => { + if (lock) { + return + } + searchInputRef.current.value = val + if (val) { + setShowClean(true) + } else { + setShowClean(false) + } + } + + return ( +
+ updateSearchKey(e.target.value)} + defaultValue={keyword || ''} + /> + +
+ +
+ + {showClean && ( +
+ +
+ )} +
+ ) +} + +export default SearchInput diff --git a/themes/starter/index.js b/themes/starter/index.js index c4f9af8c..3ae161f6 100644 --- a/themes/starter/index.js +++ b/themes/starter/index.js @@ -25,6 +25,7 @@ import CONFIG from './config' import { Style } from './style' // import { MadeWithButton } from './components/MadeWithButton' import Comment from '@/components/Comment' +import replaceSearchResult from '@/components/Mark' import ShareBar from '@/components/ShareBar' import { useGlobal } from '@/lib/global' import { loadWowJS } from '@/lib/plugins/wow' @@ -33,6 +34,7 @@ import Link from 'next/link' import { ArticleLock } from './components/ArticleLock' import { Banner } from './components/Banner' import { CTA } from './components/CTA' +import SearchInput from './components/SearchInput' import { SignInForm } from './components/SignInForm' import { SignUpForm } from './components/SignUpForm' import { SVG404 } from './components/svg/SVG404' @@ -61,7 +63,9 @@ const LayoutBase = props => { {/* 页头 */}
- {children} +
+ {children} +
{/* 页脚 */}