diff --git a/pages/search.js b/pages/search.js
index 57bc57fb..ef7cae89 100644
--- a/pages/search.js
+++ b/pages/search.js
@@ -1,5 +1,8 @@
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import { LayoutSearch } from '@/themes'
+import BLOG from '@/blog.config'
+import { useGlobal } from '@/lib/global'
+import { useRouter } from 'next/router'
export async function getStaticProps () {
const {
@@ -24,7 +27,36 @@ export async function getStaticProps () {
}
const Search = (props) => {
- return
+ const { posts } = props
+ let filteredPosts
+ const searchKey = getSearchKey()
+ // 静态过滤
+ if (searchKey) {
+ filteredPosts = posts.filter(post => {
+ const tagContent = post.tags ? post.tags.join(' ') : ''
+ const categoryContent = post.category ? post.category.join(' ') : ''
+ const searchContent = post.title + post.summary + tagContent + categoryContent
+ return searchContent.toLowerCase().includes(searchKey.toLowerCase())
+ })
+ } else {
+ filteredPosts = posts
+ }
+
+ const { locale } = useGlobal()
+ const meta = {
+ title: `${searchKey || ''} | ${locale.NAV.SEARCH} | ${BLOG.TITLE} `,
+ description: BLOG.DESCRIPTION,
+ type: 'website'
+ }
+ return
+}
+
+function getSearchKey () {
+ const router = useRouter()
+ if (router.query && router.query.s) {
+ return router.query.s
+ }
+ return null
}
export default Search
diff --git a/themes/Empty/LayoutSearch.js b/themes/Empty/LayoutSearch.js
index c7469a60..fb9244c3 100644
--- a/themes/Empty/LayoutSearch.js
+++ b/themes/Empty/LayoutSearch.js
@@ -1,31 +1,6 @@
-import { useRouter } from 'next/router'
import LayoutBase from './LayoutBase'
export const LayoutSearch = (props) => {
- const { posts } = props
- let filteredPosts
- const searchKey = getSearchKey()
- if (searchKey) {
- filteredPosts = posts.filter(post => {
- const tagContent = post.tags ? post.tags.join(' ') : ''
- const searchContent = post.title + post.summary + tagContent
- return searchContent.toLowerCase().includes(searchKey.toLowerCase())
- })
- } else {
- filteredPosts = posts
- }
-
- console.log(filteredPosts)
-
return
- Search {searchKey}
}
-
-function getSearchKey () {
- const router = useRouter()
- if (router.query && router.query.s) {
- return router.query.s
- }
- return null
-}
diff --git a/themes/Fukasawa/LayoutIndex.js b/themes/Fukasawa/LayoutIndex.js
index 5a1209c5..0158a856 100644
--- a/themes/Fukasawa/LayoutIndex.js
+++ b/themes/Fukasawa/LayoutIndex.js
@@ -3,8 +3,6 @@ import LayoutBase from './LayoutBase'
export const LayoutIndex = (props) => {
return
-
-
-
+
}
diff --git a/themes/Fukasawa/LayoutSearch.js b/themes/Fukasawa/LayoutSearch.js
index 1d77bf69..8112f850 100644
--- a/themes/Fukasawa/LayoutSearch.js
+++ b/themes/Fukasawa/LayoutSearch.js
@@ -1,30 +1,8 @@
-import { useRouter } from 'next/router'
import LayoutBase from './LayoutBase'
+import BlogListPage from './components/BlogListPage'
export const LayoutSearch = (props) => {
- let filteredPosts
- const searchKey = getSearchKey()
- if (searchKey) {
- filteredPosts = props.posts.filter(post => {
- const tagContent = post.tags ? post.tags.join(' ') : ''
- const searchContent = post.title + post.summary + tagContent
- return searchContent.toLowerCase().includes(searchKey.toLowerCase())
- })
- } else {
- filteredPosts = props.posts
- }
-
- console.log(filteredPosts)
-
return
- Search {searchKey}
+
}
-
-function getSearchKey () {
- const router = useRouter()
- if (router.query && router.query.s) {
- return router.query.s
- }
- return null
-}
diff --git a/themes/Hexo/LayoutCategoryIndex.js b/themes/Hexo/LayoutCategoryIndex.js
index 6585e290..5c6de632 100644
--- a/themes/Hexo/LayoutCategoryIndex.js
+++ b/themes/Hexo/LayoutCategoryIndex.js
@@ -25,7 +25,7 @@ export const LayoutCategoryIndex = props => {
diff --git a/themes/Hexo/LayoutSearch.js b/themes/Hexo/LayoutSearch.js
index 77be5014..3b26ad57 100644
--- a/themes/Hexo/LayoutSearch.js
+++ b/themes/Hexo/LayoutSearch.js
@@ -1,38 +1,9 @@
-import BLOG from '@/blog.config'
-import { useGlobal } from '@/lib/global'
-import { useRouter } from 'next/router'
+
import BlogPostListPage from './components/BlogPostListPage'
import LayoutBase from './LayoutBase'
export const LayoutSearch = (props) => {
- const { posts } = props
- let filteredPosts
- const searchKey = getSearchKey()
- if (searchKey) {
- filteredPosts = posts.filter(post => {
- const tagContent = post.tags ? post.tags.join(' ') : ''
- const searchContent = post.title + post.summary + tagContent
- return searchContent.toLowerCase().includes(searchKey.toLowerCase())
- })
- } else {
- filteredPosts = posts
- }
-
- const { locale } = useGlobal()
- const meta = {
- title: `${searchKey || ''} | ${locale.NAV.SEARCH} | ${BLOG.TITLE} `,
- description: BLOG.DESCRIPTION,
- type: 'website'
- }
- return
-
+ return
+
}
-
-function getSearchKey () {
- const router = useRouter()
- if (router.query && router.query.s) {
- return router.query.s
- }
- return null
-}
diff --git a/themes/Hexo/components/MenuButtonGroup.js b/themes/Hexo/components/MenuButtonGroup.js
index ee93f4a7..a968b800 100644
--- a/themes/Hexo/components/MenuButtonGroup.js
+++ b/themes/Hexo/components/MenuButtonGroup.js
@@ -11,11 +11,11 @@ const MenuButtonGroup = (props) => {
const archiveSlot = {postCount}
let links = [
- { id: 0, icon: 'fas fa-home', name: locale.NAV.INDEX, to: '/' || '/', show: true },
- { id: 1, icon: 'fas fa-th', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_HEXO.MENU_CATEGORY },
- { id: 2, icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_HEXO.MENU_TAG },
- { id: 3, icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', slot: archiveSlot, show: CONFIG_HEXO.MENU_ARCHIVE },
- { id: 4, icon: 'fas fa-user', name: locale.NAV.ABOUT, to: '/about', show: CONFIG_HEXO.MENU_ABOUT }
+ { icon: 'fas fa-home', name: locale.NAV.INDEX, to: '/' || '/', show: true },
+ { 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-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 }
]
if (customNav) {
links = links.concat(customNav)
@@ -24,11 +24,11 @@ const MenuButtonGroup = (props) => {
{links.map(link => {
if (link.show) {
const selected = (router.pathname === link.to) || (router.asPath === link.to)
- return
+ return
{link.slot}
diff --git a/themes/Hexo/components/SearchInput.js b/themes/Hexo/components/SearchInput.js
index 5ac91ad5..d6ba0884 100644
--- a/themes/Hexo/components/SearchInput.js
+++ b/themes/Hexo/components/SearchInput.js
@@ -44,10 +44,10 @@ const SearchInput = ({ currentTag, currentSearch, cRef }) => {
updateSearchKey(e.target.value)}
- defaultValue={searchKey}
+ defaultValue={currentSearch}
/>
{
- const { posts, tags } = props
- let filteredPosts
- const searchKey = getSearchKey()
- if (searchKey) {
- filteredPosts = posts.filter(post => {
- const tagContent = post.tags ? post.tags.join(' ') : ''
- const searchContent = post.title + post.summary + tagContent
- return searchContent.toLowerCase().includes(searchKey.toLowerCase())
- })
- } else {
- filteredPosts = posts
- }
-
const { locale } = useGlobal()
- const meta = {
- title: `${searchKey || ''} | ${locale.NAV.SEARCH} | ${BLOG.TITLE} `,
- description: BLOG.DESCRIPTION,
- type: 'website'
- }
+ const { posts } = props
+
return (
-
+
{' '}
- {filteredPosts.length} {locale.COMMON.RESULT_OF_SEARCH}
+ {posts.length} {locale.COMMON.RESULT_OF_SEARCH}
-
+
)
}
-
-function getSearchKey () {
- const router = useRouter()
- if (router.query && router.query.s) {
- return router.query.s
- }
- return null
-}
diff --git a/themes/NEXT/components/SearchInput.js b/themes/NEXT/components/SearchInput.js
index 2c18732f..2f6f86c4 100644
--- a/themes/NEXT/components/SearchInput.js
+++ b/themes/NEXT/components/SearchInput.js
@@ -47,12 +47,12 @@ const SearchInput = ({ currentTag, currentSearch, cRef }) => {
ref={searchInputRef}
type='text'
placeholder={currentTag ? `${locale.SEARCH.TAGS} #${currentTag}` : `${locale.SEARCH.ARTICLES}`}
- className={'w-full text-sm pl-2 transition focus:shadow-lg font-light leading-10 border-gray-300 text-black bg-gray-100 dark:bg-gray-900 dark:text-white'}
+ className={'w-full text-sm pl-4 transition focus:shadow-lg font-light leading-10 border-gray-300 text-black bg-gray-100 dark:bg-gray-900 dark:text-white'}
onKeyUp={handleKeyUp}
onChange={e => updateSearchKey(e.target.value)}
defaultValue={searchKey}
/>
- {(searchKey && searchKey.length && )}
+ {(searchKey && searchKey.length && )}
{ handleSearch(searchKey) }}>
diff --git a/themes/index.js b/themes/index.js
index 29af6e2a..79876b36 100644
--- a/themes/index.js
+++ b/themes/index.js
@@ -4,6 +4,6 @@
// export * from './Empty' // 空主题
// export * from './NEXT'
-// export * from './Fukasawa'
+export * from './Fukasawa'
+// export * from './Hexo'
// export * from './Hexo'
-export * from './Hexo'