1
1
import BLOG from '@/blog.config'
2
+ import useNotification from '@/components/Notification'
2
3
import { siteConfig } from '@/lib/config'
3
4
import { getGlobalData , getPost , getPostBlocks } from '@/lib/db/getSiteData'
5
+ import { useGlobal } from '@/lib/global'
4
6
import { getPageTableOfContents } from '@/lib/notion/getPageTableOfContents'
7
+ import { getPasswordQuery } from '@/lib/password'
5
8
import { uploadDataToAlgolia } from '@/lib/plugins/algolia'
6
9
import { checkSlugHasNoSlash , getRecommendPost } from '@/lib/utils/post'
7
10
import { getLayoutByTheme } from '@/themes/theme'
@@ -19,9 +22,11 @@ import { useEffect, useState } from 'react'
19
22
const Slug = props => {
20
23
const { post } = props
21
24
const router = useRouter ( )
25
+ const { locale } = useGlobal ( )
22
26
23
27
// 文章锁🔐
24
28
const [ lock , setLock ] = useState ( post ?. password && post ?. password !== '' )
29
+ const { showNotification, Notification } = useNotification ( )
25
30
26
31
/**
27
32
* 验证文章密码
@@ -36,6 +41,7 @@ const Slug = props => {
36
41
setLock ( false )
37
42
// 输入密码存入localStorage,下次自动提交
38
43
localStorage . setItem ( 'password_' + router . asPath , passInput )
44
+ showNotification ( locale . COMMON . ARTICLE_UNLOCK_TIPS ) // 设置解锁成功提示显示
39
45
return true
40
46
}
41
47
return false
@@ -56,10 +62,14 @@ const Slug = props => {
56
62
}
57
63
}
58
64
59
- // 从localStorage中读取上次记录 自动提交密码
60
- const passInput = localStorage . getItem ( 'password_' + router . asPath )
61
- if ( passInput ) {
62
- validPassword ( passInput )
65
+ // 读取上次记录 自动提交密码
66
+ const passInputs = getPasswordQuery ( router . asPath )
67
+ if ( passInputs . length > 0 ) {
68
+ for ( const passInput of passInputs ) {
69
+ if ( validPassword ( passInput ) ) {
70
+ break // 密码验证成功,停止尝试
71
+ }
72
+ }
63
73
}
64
74
} , [ post ] )
65
75
@@ -83,7 +93,12 @@ const Slug = props => {
83
93
theme : siteConfig ( 'THEME' ) ,
84
94
router : useRouter ( )
85
95
} )
86
- return < Layout { ...props } />
96
+ return (
97
+ < >
98
+ < Layout { ...props } />
99
+ { ! lock && < Notification /> }
100
+ </ >
101
+ )
87
102
}
88
103
89
104
export async function getStaticPaths ( ) {
0 commit comments