mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-04 15:10:23 +00:00
Hexo主题 微调
This commit is contained in:
@@ -3,23 +3,31 @@ import { useRouter } from 'next/router'
|
|||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import BlogPostListPage from './components/BlogPostListPage'
|
import BlogPostListPage from './components/BlogPostListPage'
|
||||||
import LayoutBase from './LayoutBase'
|
import LayoutBase from './LayoutBase'
|
||||||
|
import SearchInput from './components/SearchInput'
|
||||||
export const LayoutSearch = (props) => {
|
export const LayoutSearch = (props) => {
|
||||||
const { keyword } = props
|
const { keyword } = props
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const currentSearch = keyword || router?.query?.s
|
const currentSearch = keyword || router?.query?.s
|
||||||
|
let handleTextColor = false
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const container = document.getElementById('container')
|
if (currentSearch && !handleTextColor) {
|
||||||
if (container && container.innerHTML) {
|
const container = document.getElementById('container')
|
||||||
const re = new RegExp(`${currentSearch}`, 'gim')
|
if (container && container.innerHTML) {
|
||||||
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${currentSearch}</span>`)
|
const re = new RegExp(`${currentSearch}`, 'gim')
|
||||||
|
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${currentSearch}</span>`)
|
||||||
|
handleTextColor = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
100)
|
100)
|
||||||
})
|
})
|
||||||
return <LayoutBase {...props} currentSearch={currentSearch}>
|
return <LayoutBase {...props} currentSearch={currentSearch}>
|
||||||
<div ic='container'>
|
<div className='m-3'>
|
||||||
|
<SearchInput {...props}/>
|
||||||
|
</div>
|
||||||
|
<div id='container'>
|
||||||
<BlogPostListPage {...props}/>
|
<BlogPostListPage {...props}/>
|
||||||
</div>
|
</div>
|
||||||
</LayoutBase>
|
</LayoutBase>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const MenuButtonGroupTop = (props) => {
|
|||||||
const { locale } = useGlobal()
|
const { locale } = useGlobal()
|
||||||
|
|
||||||
let links = [
|
let links = [
|
||||||
|
{ icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: CONFIG_HEXO.MENU_SEARCH },
|
||||||
{ icon: 'fas fa-archive', name: locale.COMMON.ARTICLE, to: '/archive', show: CONFIG_HEXO.MENU_ARCHIVE },
|
{ icon: 'fas fa-archive', name: locale.COMMON.ARTICLE, to: '/archive', show: CONFIG_HEXO.MENU_ARCHIVE },
|
||||||
{ icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_HEXO.MENU_CATEGORY },
|
{ icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_HEXO.MENU_CATEGORY },
|
||||||
{ icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_HEXO.MENU_TAG }
|
{ icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_HEXO.MENU_TAG }
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const MenuList = (props) => {
|
|||||||
{ icon: 'fas fa-th', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_HEXO.MENU_CATEGORY },
|
{ icon: 'fas fa-th', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_HEXO.MENU_CATEGORY },
|
||||||
{ icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_HEXO.MENU_TAG },
|
{ icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_HEXO.MENU_TAG },
|
||||||
{ icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', slot: archiveSlot, show: CONFIG_HEXO.MENU_ARCHIVE },
|
{ icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', slot: archiveSlot, show: CONFIG_HEXO.MENU_ARCHIVE },
|
||||||
{ icon: 'fas fa-user', name: locale.NAV.ABOUT, to: '/about', show: CONFIG_HEXO.MENU_ABOUT }
|
{ icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: CONFIG_HEXO.MENU_SEARCH }
|
||||||
]
|
]
|
||||||
if (customNav) {
|
if (customNav) {
|
||||||
links = links.concat(customNav)
|
links = links.concat(customNav)
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { useImperativeHandle, useRef, useState } from 'react'
|
import { useImperativeHandle, useRef, useState } from 'react'
|
||||||
|
let lock = false
|
||||||
|
|
||||||
const SearchInput = ({ currentTag, currentSearch, cRef }) => {
|
const SearchInput = (props) => {
|
||||||
const [searchKey, setSearchKey] = useState(currentSearch || '')
|
const { currentSearch, cRef, className } = props
|
||||||
const [onLoading, setLoadingState] = useState(false)
|
const [onLoading, setLoadingState] = useState(false)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const searchInputRef = useRef()
|
const searchInputRef = useRef()
|
||||||
@@ -13,12 +14,12 @@ const SearchInput = ({ currentTag, currentSearch, cRef }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const handleSearch = (key) => {
|
|
||||||
|
const handleSearch = () => {
|
||||||
|
const key = searchInputRef.current.value
|
||||||
if (key && key !== '') {
|
if (key && key !== '') {
|
||||||
setLoadingState(true)
|
setLoadingState(true)
|
||||||
router.push({ pathname: '/search', query: { s: key } }).then(r => {
|
location.href = '/search/' + key
|
||||||
setLoadingState(false)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
router.push({ pathname: '/' }).then(r => {
|
router.push({ pathname: '/' }).then(r => {
|
||||||
})
|
})
|
||||||
@@ -33,12 +34,19 @@ const SearchInput = ({ currentTag, currentSearch, cRef }) => {
|
|||||||
}
|
}
|
||||||
const cleanSearch = () => {
|
const cleanSearch = () => {
|
||||||
searchInputRef.current.value = ''
|
searchInputRef.current.value = ''
|
||||||
setSearchKey('')
|
|
||||||
}
|
}
|
||||||
let lock = false
|
|
||||||
|
const [showClean, setShowClean] = useState(false)
|
||||||
const updateSearchKey = (val) => {
|
const updateSearchKey = (val) => {
|
||||||
if (!lock) {
|
if (lock) {
|
||||||
setSearchKey(val)
|
return
|
||||||
|
}
|
||||||
|
searchInputRef.current.value = val
|
||||||
|
|
||||||
|
if (val) {
|
||||||
|
setShowClean(true)
|
||||||
|
} else {
|
||||||
|
setShowClean(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function lockSearchInput () {
|
function lockSearchInput () {
|
||||||
@@ -48,8 +56,9 @@ const SearchInput = ({ currentTag, currentSearch, cRef }) => {
|
|||||||
function unLockSearchInput () {
|
function unLockSearchInput () {
|
||||||
lock = false
|
lock = false
|
||||||
}
|
}
|
||||||
return <div className='flex'>
|
|
||||||
<input
|
return <div className={'flex w-full bg-gray-100 ' + className}>
|
||||||
|
<input
|
||||||
ref={searchInputRef}
|
ref={searchInputRef}
|
||||||
type='text'
|
type='text'
|
||||||
className={'w-full rounded-lg text-sm pl-5 transition focus:shadow-lg dark:text-gray-300 font-light leading-10 text-black bg-gray-100 dark:bg-gray-500'}
|
className={'w-full rounded-lg text-sm pl-5 transition focus:shadow-lg dark:text-gray-300 font-light leading-10 text-black bg-gray-100 dark:bg-gray-500'}
|
||||||
@@ -61,12 +70,12 @@ const SearchInput = ({ currentTag, currentSearch, cRef }) => {
|
|||||||
defaultValue={currentSearch}
|
defaultValue={currentSearch}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className='-ml-8 cursor-pointer float-right items-center justify-center py-2'
|
<div className='-ml-8 cursor-pointer float-right items-center justify-center py-2'
|
||||||
onClick={() => { handleSearch(searchKey) }}>
|
onClick={handleSearch}>
|
||||||
<i className={`hover:text-black transform duration-200 text-gray-500 dark:text-gray-200 cursor-pointer fas ${onLoading ? 'fa-spinner animate-spin' : 'fa-search'}`} />
|
<i className={`hover:text-black transform duration-200 text-gray-500 dark:text-gray-200 cursor-pointer fas ${onLoading ? 'fa-spinner animate-spin' : 'fa-search'}`} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{(searchKey && searchKey.length &&
|
{(showClean &&
|
||||||
<div className='-ml-12 cursor-pointer float-right items-center justify-center py-2'>
|
<div className='-ml-12 cursor-pointer float-right items-center justify-center py-2'>
|
||||||
<i className='hover:text-black transform duration-200 text-gray-400 dark:text-gray-300 cursor-pointer fas fa-times' onClick={cleanSearch} />
|
<i className='hover:text-black transform duration-200 text-gray-400 dark:text-gray-300 cursor-pointer fas fa-times' onClick={cleanSearch} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ export default function SideRight (props) {
|
|||||||
showCategory,
|
showCategory,
|
||||||
showTag
|
showTag
|
||||||
} = props
|
} = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='w-96 space-y-4 hidden lg:block'>
|
<div className={'w-80 space-y-4 hidden lg:block'}>
|
||||||
<InfoCard {...props}/>
|
<InfoCard {...props}/>
|
||||||
<Card>
|
<Card>
|
||||||
<div className='ml-2 mb-3 font-sans'>
|
<div className='ml-2 mb-3 font-sans'>
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ const TopNav = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Collapse isOpen={isOpen} className='shadow-xl'>
|
<Collapse isOpen={isOpen} className='shadow-xl'>
|
||||||
<div className='bg-white pt-1 py-2 px-5 flex lg:hidden'>
|
<div className='bg-white pt-1 py-2 px-5 lg:hidden'>
|
||||||
<MenuList {...props}/>
|
<MenuList {...props}/>
|
||||||
</div>
|
</div>
|
||||||
</Collapse>
|
</Collapse>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// export * from './Empty' // 空主题
|
// export * from './Empty' // 空主题
|
||||||
export * from './NEXT'
|
// export * from './NEXT'
|
||||||
// export * from './Fukasawa'
|
// export * from './Fukasawa'
|
||||||
// export * from './Hexo'
|
export * from './Hexo'
|
||||||
// export * from './Medium'
|
// export * from './Medium'
|
||||||
|
|||||||
Reference in New Issue
Block a user