Merge pull request #1632 from KazooTTT/fix-algolia

Fix algolia
This commit is contained in:
tangly1024
2023-11-20 17:32:48 +08:00
committed by GitHub
2 changed files with 68 additions and 37 deletions

View File

@@ -102,43 +102,74 @@ export default function AlgoliaSearchModal({ cRef }) {
}
return (
<div id='search-wrapper' className={`${isModalOpen ? 'opacity-100' : 'invisible opacity-0 pointer-events-none'} z-30 fixed h-screen w-screen left-0 top-0 mt-12 flex items-start justify-center`}>
{/* 模态框 */}
<div className={`${isModalOpen ? 'opacity-100' : 'invisible opacity-0 translate-y-10'} flex flex-col justify-between w-full min-h-[10rem] max-w-xl dark:bg-hexo-black-gray dark:border-gray-800 bg-white dark:bg- p-5 rounded-lg z-50 shadow border hover:border-blue-600 duration-300 transition-all `}>
<div className='flex justify-between items-center'>
<div className='text-2xl text-blue-600 font-bold'>搜索</div>
<div><i className="text-gray-600 fa-solid fa-xmark p-1 cursor-pointer hover:text-blue-600" onClick={closeModal} ></i></div>
</div>
<input type="text" placeholder="在这里输入搜索关键词..." onChange={(e) => handleInputChange(e)}
className="text-black dark:text-gray-200 bg-gray-50 dark:bg-gray-600 outline-blue-500 w-full px-4 my-2 py-1 mb-4 border rounded-md" />
{/* 标签组 */}
<div className='mb-4'>
<TagGroups/>
</div>
<ul>
{searchResults.map((result) => (
<li key={result.objectID} className="replace my-2">
<a href={`${siteConfig('SUB_PATH')}/${result.slug}`} className="font-bold hover:text-blue-600 text-black dark:text-gray-200">
{result.title}
</a>
</li>
))}
</ul>
<Pagination totalPage={totalPage} page={page} switchPage={switchPage}/>
<div>{totalHit > 0 && <div>共搜索到 {totalHit} 条结果用时 {useTime} 毫秒</div> }</div>
<div className='text-gray-600 mt-2'><span><i className="fa-brands fa-algolia"></i> Algolia </span> </div>
</div>
{/* 遮罩 */}
<div onClick={closeModal} className="z-30 fixed top-0 left-0 w-full h-full flex items-center justify-center glassmorphism" />
<div
id="search-wrapper"
className={`${
isModalOpen ? 'opacity-100' : 'invisible opacity-0 pointer-events-none'
} z-30 fixed h-screen w-screen left-0 top-0 mt-12 flex items-start justify-center`}
>
{/* 模态框 */}
<div
className={`${
isModalOpen ? 'opacity-100' : 'invisible opacity-0 translate-y-10'
} flex flex-col justify-between w-full min-h-[10rem] max-w-xl dark:bg-hexo-black-gray dark:border-gray-800 bg-white dark:bg- p-5 rounded-lg z-50 shadow border hover:border-blue-600 duration-300 transition-all `}
>
<div className="flex justify-between items-center">
<div className="text-2xl text-blue-600 font-bold">搜索</div>
<div>
<i
className="text-gray-600 fa-solid fa-xmark p-1 cursor-pointer hover:text-blue-600"
onClick={closeModal}
></i>
</div>
</div>
<input
type="text"
placeholder="在这里输入搜索关键词..."
onChange={e => handleInputChange(e)}
className="text-black dark:text-gray-200 bg-gray-50 dark:bg-gray-600 outline-blue-500 w-full px-4 my-2 py-1 mb-4 border rounded-md"
/>
{/* 标签组 */}
<div className="mb-4">
<TagGroups />
</div>
<ul>
{searchResults.map(result => (
<li key={result.objectID} className="replace my-2">
<a
href={`${siteConfig('SUB_PATH', '')}/${result.slug}`}
className="font-bold hover:text-blue-600 text-black dark:text-gray-200"
>
{result.title}
</a>
</li>
))}
</ul>
<Pagination totalPage={totalPage} page={page} switchPage={switchPage} />
<div>
{totalHit > 0 && (
<div>
共搜索到 {totalHit} 条结果用时 {useTime} 毫秒
</div>
)}
</div>
<div className="text-gray-600 mt-2">
<span>
<i className="fa-brands fa-algolia"></i> Algolia
</span>{' '}
</div>
</div>
{/* 遮罩 */}
<div
onClick={closeModal}
className="z-30 fixed top-0 left-0 w-full h-full flex items-center justify-center glassmorphism"
/>
</div>
)
}

View File

@@ -42,7 +42,7 @@ const uploadDataToAlgolia = async(post) => {
if (!existed || !existed?.lastEditedDate || !existed?.lastIndexDate) {
needUpdateIndex = true
} else {
const lastEditedDate = new Date(existed.lastEditedDate)
const lastEditedDate = new Date(post.lastEditedDate)
const lastIndexDate = new Date(existed.lastIndexDate)
if (lastEditedDate.getTime() > lastIndexDate.getTime()) {
needUpdateIndex = true