mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-04 15:10:23 +00:00
@@ -25,6 +25,10 @@ const Comment = ({ frontMatter }) => {
|
|||||||
return (
|
return (
|
||||||
<div className='comment mt-5 text-gray-800 dark:text-gray-300'>
|
<div className='comment mt-5 text-gray-800 dark:text-gray-300'>
|
||||||
<Tabs>
|
<Tabs>
|
||||||
|
{BLOG.COMMENT_UTTERRANCES_REPO && (<div key='Utterance'>
|
||||||
|
<UtterancesComponent issueTerm={frontMatter.id} className='px-2' />
|
||||||
|
</div>)}
|
||||||
|
|
||||||
{BLOG.COMMENT_CUSDIS_APP_ID && (<div key='Cusdis'>
|
{BLOG.COMMENT_CUSDIS_APP_ID && (<div key='Cusdis'>
|
||||||
<ReactCusdis
|
<ReactCusdis
|
||||||
lang={locale.LOCALE.toLowerCase()}
|
lang={locale.LOCALE.toLowerCase()}
|
||||||
@@ -38,10 +42,6 @@ const Comment = ({ frontMatter }) => {
|
|||||||
/>
|
/>
|
||||||
</div>)}
|
</div>)}
|
||||||
|
|
||||||
{BLOG.COMMENT_UTTERRANCES_REPO && (<div key='Utterance'>
|
|
||||||
<UtterancesComponent issueTerm={frontMatter.id} className='px-2' />
|
|
||||||
</div>)}
|
|
||||||
|
|
||||||
{BLOG.COMMENT_GITALK_CLIENT_ID && (<div key='GitTalk'>
|
{BLOG.COMMENT_GITALK_CLIENT_ID && (<div key='GitTalk'>
|
||||||
<GitalkComponent
|
<GitalkComponent
|
||||||
options={{
|
options={{
|
||||||
|
|||||||
@@ -43,9 +43,8 @@ const Tabs = ({ className, children }) => {
|
|||||||
</ul>
|
</ul>
|
||||||
<div>
|
<div>
|
||||||
{children.map((item, index) => {
|
{children.map((item, index) => {
|
||||||
return <section key={index}
|
return <section key={index} className={ 'animate__animated animate__fadeIn animate__faster'}>
|
||||||
className={`${currentTab === index ? 'block animate__animated animate__fadeIn animate__faster' : 'hidden'}`}>
|
{currentTab === index && item}
|
||||||
{item}
|
|
||||||
</section>
|
</section>
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -63,7 +63,9 @@ export async function getStaticProps ({ params: { keyword } }) {
|
|||||||
const page = await getDataFromCache(cacheKey)
|
const page = await getDataFromCache(cacheKey)
|
||||||
const tagContent = post.tags ? post.tags.join(' ') : ''
|
const tagContent = post.tags ? post.tags.join(' ') : ''
|
||||||
const categoryContent = post.category ? post.category.join(' ') : ''
|
const categoryContent = post.category ? post.category.join(' ') : ''
|
||||||
let indexContent = [post.title, post.summary, tagContent, categoryContent]
|
const articleInfo = post.title + post.summary + tagContent + categoryContent
|
||||||
|
let hit = articleInfo.indexOf(keyword) > -1
|
||||||
|
let indexContent = [post.summary]
|
||||||
console.log('搜索是否命中缓存', page !== null)
|
console.log('搜索是否命中缓存', page !== null)
|
||||||
if (page !== null) {
|
if (page !== null) {
|
||||||
const contentIds = Object.keys(page.block)
|
const contentIds = Object.keys(page.block)
|
||||||
@@ -74,16 +76,19 @@ export async function getStaticProps ({ params: { keyword } }) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
post.results = []
|
post.results = []
|
||||||
let hit = false
|
let hitCount = 0
|
||||||
const re = new RegExp(`${keyword}`, 'g')
|
const re = new RegExp(`${keyword}`, 'g')
|
||||||
indexContent.forEach(c => {
|
indexContent.forEach((c, i) => {
|
||||||
const index = c.toLowerCase().indexOf(keyword.toLowerCase())
|
const index = c.toLowerCase().indexOf(keyword.toLowerCase())
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
hit = true
|
hit = true
|
||||||
const referText = c?.replace(re, `<span class='text-red-500'>${keyword}</span>`)
|
const referText = c?.replace(re, `<span class='text-red-500'>${keyword}</span>`)
|
||||||
post.results.push(`<span>${referText}</span>`)
|
post.results.push(`<span>${referText}</span>`)
|
||||||
|
hitCount += 1
|
||||||
} else {
|
} else {
|
||||||
post.results.push(`<span>${c}</span>`)
|
if ((post.results.length - 1) / hitCount < 3 || i === 0) {
|
||||||
|
post.results.push(`<span>${c}</span>`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ const SearchInput = ({ currentTag, currentSearch, cRef }) => {
|
|||||||
{(showClean && <i className='fas fa-times text-gray-300 float-right m-3 cursor-pointer' onClick={cleanSearch} />)}
|
{(showClean && <i className='fas fa-times text-gray-300 float-right m-3 cursor-pointer' onClick={cleanSearch} />)}
|
||||||
|
|
||||||
<div className='p-3 bg-gray-50 flex border-l dark:border-gray-700 dark:hover:bg-gray-800 dark:bg-gray-600 justify-center items-center cursor-pointer'
|
<div className='p-3 bg-gray-50 flex border-l dark:border-gray-700 dark:hover:bg-gray-800 dark:bg-gray-600 justify-center items-center cursor-pointer'
|
||||||
onClick={handleKeyUp}>
|
onClick={handleSearch}>
|
||||||
<i className={`${onLoading ? 'fa-spinner animate-spin ' : 'fa-search'} fas hover:scale-125 hover:text-black transform duration-200 dark:text-gray-300 dark:hover:text-white text-gray-600 cursor-pointer`} />
|
<i className={`${onLoading ? 'fa-spinner animate-spin ' : 'fa-search'} fas hover:scale-125 hover:text-black transform duration-200 dark:text-gray-300 dark:hover:text-white text-gray-600 cursor-pointer`} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user