移除Preact框架、引入react-hook检查

This commit is contained in:
tangly1024
2022-11-30 22:08:15 +08:00
parent c527673b84
commit 2f76a7314c
12 changed files with 54 additions and 171 deletions

View File

@@ -20,6 +20,17 @@ const Slug = props => {
const { post, siteInfo } = props
const router = Router.useRouter()
// 文章锁🔐
const [lock, setLock] = React.useState(true)
React.useEffect(() => {
if (post?.password && post?.password !== '') {
setLock(true)
} else {
setLock(false)
}
}, [post])
if (!post) {
changeLoadingState(true)
setTimeout(() => {
@@ -38,16 +49,6 @@ const Slug = props => {
changeLoadingState(false)
// 文章锁🔐
const [lock, setLock] = React.useState(post?.password && post?.password !== '')
React.useEffect(() => {
if (post?.password && post?.password !== '') {
setLock(true)
} else {
setLock(false)
}
}, [post])
/**
* 验证文章密码
* @param {*} result

View File

@@ -5,8 +5,9 @@ import * as ThemeMap from '@/themes'
const Search = props => {
const { posts, siteInfo } = props
const router = useRouter()
let filteredPosts
const searchKey = getSearchKey()
const searchKey = getSearchKey(router)
// 静态过滤
if (searchKey) {
filteredPosts = posts.filter(post => {
@@ -61,8 +62,7 @@ export async function getStaticProps() {
}
}
function getSearchKey() {
const router = useRouter()
function getSearchKey(router) {
if (router.query && router.query.s) {
return router.query.s
}