1
- import Logo from './Logo'
2
- import GroupCategory from './GroupCategory'
3
- import { MenuList } from './MenuList'
4
- import GroupTag from './GroupTag'
5
- import SearchInput from './SearchInput'
6
- import SiteInfo from './SiteInfo'
7
- import Catalog from './Catalog'
8
- import Announcement from './Announcement'
9
- import { useRouter } from 'next/router'
10
1
import DarkModeButton from '@/components/DarkModeButton'
11
- import SocialButton from './SocialButton'
12
- import CONFIG from '@/themes/fukasawa/config'
13
2
import { AdSlot } from '@/components/GoogleAdsense'
14
3
import { siteConfig } from '@/lib/config'
15
- import MailChimpForm from './MailChimpForm'
16
4
import { useGlobal } from '@/lib/global'
17
- import { useEffect , useMemo , useState } from 'react'
18
5
import { isBrowser } from '@/lib/utils'
6
+ import CONFIG from '@/themes/fukasawa/config'
19
7
import { debounce } from 'lodash'
8
+ import { useRouter } from 'next/router'
9
+ import { useEffect , useMemo , useState } from 'react'
10
+ import Announcement from './Announcement'
11
+ import Catalog from './Catalog'
12
+ import GroupCategory from './GroupCategory'
13
+ import GroupTag from './GroupTag'
14
+ import Logo from './Logo'
15
+ import MailChimpForm from './MailChimpForm'
16
+ import { MenuList } from './MenuList'
17
+ import SearchInput from './SearchInput'
18
+ import SiteInfo from './SiteInfo'
19
+ import SocialButton from './SocialButton'
20
20
21
21
/**
22
22
* 侧边栏
23
23
* @param {* } props
24
24
* @returns
25
25
*/
26
26
function AsideLeft ( props ) {
27
- const { tagOptions, currentTag, categoryOptions, currentCategory, post, slot, notice } = props
27
+ const {
28
+ tagOptions,
29
+ currentTag,
30
+ categoryOptions,
31
+ currentCategory,
32
+ post,
33
+ slot,
34
+ notice
35
+ } = props
28
36
const router = useRouter ( )
29
37
const { fullWidth } = useGlobal ( )
30
38
31
- const FUKASAWA_SIDEBAR_COLLAPSE_SATUS_DEFAULT = fullWidth || siteConfig ( 'FUKASAWA_SIDEBAR_COLLAPSE_SATUS_DEFAULT' , null , CONFIG )
39
+ const FUKASAWA_SIDEBAR_COLLAPSE_SATUS_DEFAULT =
40
+ fullWidth ||
41
+ siteConfig ( 'FUKASAWA_SIDEBAR_COLLAPSE_SATUS_DEFAULT' , null , CONFIG )
42
+
43
+ const FUKASAWA_SIDEBAR_COLLAPSE_ON_SCROLL = siteConfig (
44
+ 'FUKASAWA_SIDEBAR_COLLAPSE_ON_SCROLL' ,
45
+ false ,
46
+ CONFIG
47
+ )
48
+
49
+ const FUKASAWA_SIDEBAR_COLLAPSE_BUTTON = siteConfig (
50
+ 'FUKASAWA_SIDEBAR_COLLAPSE_BUTTON' ,
51
+ null ,
52
+ CONFIG
53
+ )
32
54
33
55
// 侧边栏折叠从 本地存储中获取 open 状态的初始值
34
56
const [ isCollapsed , setIsCollapse ] = useState ( ( ) => {
35
57
if ( typeof window !== 'undefined' ) {
36
- return localStorage . getItem ( 'fukasawa-sidebar-collapse' ) === 'true' || FUKASAWA_SIDEBAR_COLLAPSE_SATUS_DEFAULT
58
+ return (
59
+ localStorage . getItem ( 'fukasawa-sidebar-collapse' ) === 'true' ||
60
+ FUKASAWA_SIDEBAR_COLLAPSE_SATUS_DEFAULT
61
+ )
37
62
}
38
63
return FUKASAWA_SIDEBAR_COLLAPSE_SATUS_DEFAULT
39
64
} )
@@ -69,7 +94,7 @@ function AsideLeft(props) {
69
94
70
95
// 自动折叠侧边栏 onResize 窗口宽度小于1366 || 滚动条滚动至页面的300px时 ; 将open设置为false
71
96
useEffect ( ( ) => {
72
- if ( ! siteConfig ( ' FUKASAWA_SIDEBAR_COLLAPSE_ON_SCROLL' , false , CONFIG ) ) {
97
+ if ( ! FUKASAWA_SIDEBAR_COLLAPSE_ON_SCROLL ) {
73
98
return
74
99
}
75
100
const handleResize = debounce ( ( ) => {
@@ -92,73 +117,89 @@ function AsideLeft(props) {
92
117
}
93
118
}
94
119
} , [ ] )
95
-
96
-
97
- return < div className = { `sideLeft relative ${ isCollapsed ? 'w-0' : 'w-80' } duration-300 transition-all bg-white dark:bg-hexo-black-gray min-h-screen hidden lg:block z-20` } >
98
- { /* 折叠按钮 */ }
99
- { siteConfig ( 'FUKASAWA_SIDEBAR_COLLAPSE_BUTTON' , null , CONFIG ) && < div className = { `${ position } hidden lg:block fixed top-0 cursor-pointer hover:scale-110 duration-300 px-3 py-2 dark:text-white` } onClick = { toggleOpen } >
100
- { isCollapsed ? < i className = "fa-solid fa-indent text-xl" > </ i > : < i className = 'fas fa-bars text-xl' > </ i > }
101
- </ div > }
102
-
103
- < div className = { `h-full ${ isCollapsed ? 'hidden' : 'p-8' } ` } >
104
-
105
- < Logo { ...props } />
106
-
107
- < section className = 'siteInfo flex flex-col dark:text-gray-300 pt-8' >
108
- { siteConfig ( 'DESCRIPTION' ) }
109
- </ section >
110
-
111
- < section className = 'flex flex-col text-gray-600' >
112
- < div className = 'w-12 my-4' />
113
- < MenuList { ...props } />
114
- </ section >
115
-
116
- < section className = 'flex flex-col text-gray-600' >
117
- < div className = 'w-12 my-4' />
118
- < SearchInput { ...props } />
119
- </ section >
120
-
121
- < section className = 'flex flex-col dark:text-gray-300' >
122
- < div className = 'w-12 my-4' />
123
- < Announcement post = { notice } />
124
- </ section >
125
-
126
- < section >
127
- < MailChimpForm />
128
- </ section >
129
-
130
- < section >
131
- < AdSlot type = 'in-article' />
132
- </ section >
133
-
134
- { router . asPath !== '/tag' && < section className = 'flex flex-col' >
135
- < div className = 'w-12 my-4' />
136
- < GroupTag tags = { tagOptions } currentTag = { currentTag } />
137
- </ section > }
138
-
139
- { router . asPath !== '/category' && < section className = 'flex flex-col' >
140
- < div className = 'w-12 my-4' />
141
- < GroupCategory categories = { categoryOptions } currentCategory = { currentCategory } />
142
- </ section > }
143
-
144
- < section className = 'flex flex-col' >
145
- < div className = 'w-12 my-4' />
146
- < SocialButton />
147
- < SiteInfo />
148
- </ section >
149
-
150
- < section className = 'flex justify-center dark:text-gray-200 pt-4' >
151
- < DarkModeButton />
152
- </ section >
153
-
154
- < section className = 'sticky top-0 pt-12 flex flex-col max-h-screen ' >
155
- < Catalog toc = { post ?. toc } />
156
- < div className = 'flex justify-center' >
157
- < div > { slot } </ div >
158
- </ div >
159
- </ section >
120
+
121
+ return (
122
+ < div
123
+ className = { `sideLeft relative ${ isCollapsed ? 'w-0' : 'w-80' } duration-300 transition-all bg-white dark:bg-hexo-black-gray min-h-screen hidden lg:block z-20` } >
124
+ { /* 悬浮的折叠按钮 */ }
125
+ { FUKASAWA_SIDEBAR_COLLAPSE_BUTTON && (
126
+ < div
127
+ className = { `${ position } hidden lg:block fixed top-0 cursor-pointer hover:scale-110 duration-300 px-3 py-2 dark:text-white` }
128
+ onClick = { toggleOpen } >
129
+ { isCollapsed ? (
130
+ < i className = 'fa-solid fa-indent text-xl' > </ i >
131
+ ) : (
132
+ < i className = 'fas fa-bars text-xl' > </ i >
133
+ ) }
160
134
</ div >
135
+ ) }
136
+
137
+ < div className = { `h-full ${ isCollapsed ? 'hidden' : 'p-8' } ` } >
138
+ < Logo { ...props } />
139
+
140
+ < section className = 'siteInfo flex flex-col dark:text-gray-300 pt-8' >
141
+ { siteConfig ( 'DESCRIPTION' ) }
142
+ </ section >
143
+
144
+ < section className = 'flex flex-col text-gray-600' >
145
+ < div className = 'w-12 my-4' />
146
+ < MenuList { ...props } />
147
+ </ section >
148
+
149
+ < section className = 'flex flex-col text-gray-600' >
150
+ < div className = 'w-12 my-4' />
151
+ < SearchInput { ...props } />
152
+ </ section >
153
+
154
+ < section className = 'flex flex-col dark:text-gray-300' >
155
+ < div className = 'w-12 my-4' />
156
+ < Announcement post = { notice } />
157
+ </ section >
158
+
159
+ < section >
160
+ < MailChimpForm />
161
+ </ section >
162
+
163
+ < section >
164
+ < AdSlot type = 'in-article' />
165
+ </ section >
166
+
167
+ { router . asPath !== '/tag' && (
168
+ < section className = 'flex flex-col' >
169
+ < div className = 'w-12 my-4' />
170
+ < GroupTag tags = { tagOptions } currentTag = { currentTag } />
171
+ </ section >
172
+ ) }
173
+
174
+ { router . asPath !== '/category' && (
175
+ < section className = 'flex flex-col' >
176
+ < div className = 'w-12 my-4' />
177
+ < GroupCategory
178
+ categories = { categoryOptions }
179
+ currentCategory = { currentCategory }
180
+ />
181
+ </ section >
182
+ ) }
183
+
184
+ < section className = 'flex flex-col' >
185
+ < div className = 'w-12 my-4' />
186
+ < SocialButton />
187
+ < SiteInfo />
188
+ </ section >
189
+
190
+ < section className = 'flex justify-center dark:text-gray-200 pt-4' >
191
+ < DarkModeButton />
192
+ </ section >
193
+
194
+ < section className = 'sticky top-0 pt-12 flex flex-col max-h-screen ' >
195
+ < Catalog toc = { post ?. toc } />
196
+ < div className = 'flex justify-center' >
197
+ < div > { slot } </ div >
198
+ </ div >
199
+ </ section >
200
+ </ div >
161
201
</ div >
202
+ )
162
203
}
163
204
164
205
export default AsideLeft
0 commit comments