Skip to content

Commit c33ec22

Browse files
committed
Gitbook 主题微调
1 parent 96d5e2e commit c33ec22

11 files changed

+171
-92
lines changed

components/ThemeSwitch.js

+87-47
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,126 @@
11
import { useGlobal } from '@/lib/global'
2-
import { useState } from 'react'
3-
import { Draggable } from './Draggable'
2+
import LANGS from '@/lib/lang'
3+
import { getQueryParam } from '@/lib/utils'
44
import { THEMES } from '@/themes/theme'
55
import { useRouter } from 'next/router'
6+
import { useState } from 'react'
67
import DarkModeButton from './DarkModeButton'
7-
import { getQueryParam } from '@/lib/utils'
8-
import LANGS from '@/lib/lang'
8+
import { Draggable } from './Draggable'
99
/**
1010
*
1111
* @returns 主题切换
1212
*/
1313
const ThemeSwitch = () => {
14-
const { theme, lang, changeLang, locale, isDarkMode, toggleDarkMode } = useGlobal()
14+
const { theme, lang, changeLang, locale, isDarkMode, toggleDarkMode } =
15+
useGlobal()
1516
const router = useRouter()
1617
const currentTheme = getQueryParam(router.asPath, 'theme') || theme
1718
// const currentLang = getQueryParam(router.asPath, 'lang') || lang
1819
const [isLoading, setIsLoading] = useState(false)
1920

2021
// 修改当前路径url中的 theme 参数
2122
// 例如 http://localhost?theme=hexo 跳转到 http://localhost?theme=newTheme
22-
const onThemeSelectChange = (e) => {
23-
document.ontouchmove = document.ontouchend = document.onmousemove = document.onmouseup = null
23+
const onThemeSelectChange = e => {
24+
document.ontouchmove =
25+
document.ontouchend =
26+
document.onmousemove =
27+
document.onmouseup =
28+
null
2429
setIsLoading(true)
2530
const newTheme = e.target.value
2631
const query = router.query
2732
query.theme = newTheme
2833
router.push({ pathname: router.pathname, query }).then(() => {
2934
setTimeout(() => {
3035
setIsLoading(false)
31-
}, 500);
36+
}, 500)
3237
})
3338
}
3439

35-
const onLangSelectChange = (e) => {
36-
document.ontouchmove = document.ontouchend = document.onmousemove = document.onmouseup = null
40+
const onLangSelectChange = e => {
41+
document.ontouchmove =
42+
document.ontouchend =
43+
document.onmousemove =
44+
document.onmouseup =
45+
null
3746
const newLang = e.target.value
3847
changeLang(newLang)
3948
}
4049

41-
return (<>
42-
<Draggable>
43-
<div id="draggableBox" style={{ left: '0px', top: '80vh' }} className="fixed group space-y-2 overflow-hidden z-50 p-3 flex flex-col items-start dark:text-white bg-white dark:bg-black rounded-xl shadow-lg ">
44-
{/* 深色按钮 */}
45-
<div className="text-sm flex items-center w-0 group-hover:w-32 transition-all duration-200">
46-
<DarkModeButton />
47-
<div onClick={toggleDarkMode} className='cursor-pointer w-0 group-hover:w-24 transition-all duration-200 overflow-hidden whitespace-nowrap pl-1 h-auto'>{isDarkMode ? locale.MENU.DARK_MODE : locale.MENU.LIGHT_MODE}</div>
48-
</div>
50+
return (
51+
<>
52+
<Draggable>
53+
<div
54+
id='draggableBox'
55+
style={{ left: '0px', top: '80vh' }}
56+
className='fixed group hover:scale-105 transition-all space-y-2 overflow-hidden z-50 p-3 flex flex-col items-start dark:text-white bg-white dark:bg-black rounded-xl shadow-lg '>
57+
{/* 主题切换按钮 */}
58+
<div className='text-sm flex items-center group-hover:w-32 transition-all duration-200'>
59+
<i className='fa-solid fa-palette w-5' />
60+
<div className='w-0 group-hover:w-24 transition-all duration-200 overflow-hidden'>
61+
<label htmlFor='themeSelect' className='sr-only'>
62+
{locale.COMMON.THEME}
63+
</label>
64+
<select
65+
id='themeSelect'
66+
value={currentTheme}
67+
onChange={onThemeSelectChange}
68+
name='themes'
69+
className='pl-1 bg-gray-50 dark:bg-black appearance-none outline-none dark:text-white uppercase cursor-pointer'>
70+
{THEMES?.map(t => {
71+
return (
72+
<option key={t} value={t}>
73+
{t}
74+
</option>
75+
)
76+
})}
77+
</select>
78+
</div>
79+
</div>
4980

50-
{/* 翻译按钮 */}
51-
<div className="text-sm flex items-center group-hover:w-32 transition-all duration-200">
52-
<i className="fa-solid fa-language w-5" />
53-
<div className='w-0 group-hover:w-24 transition-all duration-200 overflow-hidden'>
54-
<label htmlFor="langSelect" className="sr-only">选择语言:</label>
55-
<select id="langSelect" value={lang} onChange={onLangSelectChange} name="themes" className='pl-1 bg-gray-50 dark:bg-black appearance-none outline-none dark:text-white uppercase cursor-pointer'>
56-
{Object.keys(LANGS)?.map(t => {
57-
return <option key={t} value={t}>{LANGS[t].LOCALE}</option>
58-
})}
59-
</select>
60-
</div>
61-
</div>
81+
{/* 深色按钮 */}
82+
<div className='text-sm flex items-center w-0 group-hover:w-32 transition-all duration-200'>
83+
<DarkModeButton />
84+
<div
85+
onClick={toggleDarkMode}
86+
className='cursor-pointer w-0 group-hover:w-24 transition-all duration-200 overflow-hidden whitespace-nowrap pl-1 h-auto'>
87+
{isDarkMode ? locale.MENU.DARK_MODE : locale.MENU.LIGHT_MODE}
88+
</div>
89+
</div>
6290

63-
{/* 主题切换按钮 */}
64-
<div className="text-sm flex items-center group-hover:w-32 transition-all duration-200">
65-
<i className="fa-solid fa-palette w-5" />
66-
<div className='w-0 group-hover:w-24 transition-all duration-200 overflow-hidden'>
67-
<label htmlFor="themeSelect" className="sr-only">选择主题:</label>
68-
<select id="themeSelect" value={currentTheme} onChange={onThemeSelectChange} name="themes" className='pl-1 bg-gray-50 dark:bg-black appearance-none outline-none dark:text-white uppercase cursor-pointer'>
69-
{THEMES?.map(t => {
70-
return <option key={t} value={t}>{t}</option>
71-
})}
72-
</select>
73-
</div>
74-
</div>
91+
{/* 翻译按钮 */}
92+
<div className='text-sm flex items-center group-hover:w-32 transition-all duration-200'>
93+
<i className='fa-solid fa-language w-5' />
94+
<div className='w-0 group-hover:w-24 transition-all duration-200 overflow-hidden'>
95+
<label htmlFor='langSelect' className='sr-only'>
96+
选择语言:
97+
</label>
98+
<select
99+
id='langSelect'
100+
value={lang}
101+
onChange={onLangSelectChange}
102+
name='themes'
103+
className='pl-1 bg-gray-50 dark:bg-black appearance-none outline-none dark:text-white uppercase cursor-pointer'>
104+
{Object.keys(LANGS)?.map(t => {
105+
return (
106+
<option key={t} value={t}>
107+
{LANGS[t].LOCALE}
108+
</option>
109+
)
110+
})}
111+
</select>
75112
</div>
76-
</Draggable>
113+
</div>
114+
</div>
115+
</Draggable>
77116

78-
{/* 切换主题加载时的全屏遮罩 */}
79-
<div className={`${isLoading ? 'opacity-90 ' : 'opacity-0'}
117+
{/* 切换主题加载时的全屏遮罩 */}
118+
<div
119+
className={`${isLoading ? 'opacity-90 ' : 'opacity-0'}
80120
w-screen h-screen glassmorphism bg-black text-white shadow-text flex justify-center items-center
81121
transition-all fixed top-0 left-0 pointer-events-none duration-1000 z-50 shadow-inner`}>
82-
<i className='text-3xl mr-5 fas fa-spinner animate-spin' />
83-
</div>
122+
<i className='text-3xl mr-5 fas fa-spinner animate-spin' />
123+
</div>
84124
</>
85125
)
86126
}

lib/lang/en-US.js

+3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ export default {
1414
INDEX: 'Home',
1515
RSS: 'RSS',
1616
SEARCH: 'Search',
17+
NAVIGATOR: 'NAV',
1718
ABOUT: 'About',
1819
MAIL: 'E-Mail',
1920
ARCHIVE: 'Archive'
2021
},
2122
COMMON: {
23+
THEME: 'Theme',
24+
ARTICLE_LIST: 'Article List',
2225
MORE: 'More',
2326
NO_MORE: 'No More',
2427
LATEST_POSTS: 'Latest posts',

lib/lang/zh-CN.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export default {
2020
ARCHIVE: '归档'
2121
},
2222
COMMON: {
23+
THEME: 'Theme',
24+
ARTICLE_LIST: '文章列表',
2325
MORE: '更多',
2426
NO_MORE: '没有更多了',
2527
LATEST_POSTS: '最新发布',
@@ -63,7 +65,7 @@ export default {
6365
MINUTE: '分钟',
6466
WORD_COUNT: '字数',
6567
READ_TIME: '阅读时长',
66-
NEXT_POST:'下一篇'
68+
NEXT_POST: '下一篇'
6769
},
6870
PAGINATION: {
6971
PREV: '上页',

lib/lang/zh-HK.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,47 @@ export default {
55
RSS: '訂閱',
66
SEARCH: '搜尋',
77
ABOUT: '關於',
8-
MAIL: '電郵'
8+
MAIL: '電郵',
9+
NAVIGATOR: '導航',
10+
ARCHIVE: '封存'
11+
},
12+
COMMON: {
13+
ARTICLE_LIST: '文章列表',
14+
MORE: '更多',
15+
NO_MORE: '沒有更多了',
16+
LATEST_POSTS: '最新文章',
17+
TAGS: '標籤',
18+
NO_TAG: '無標籤',
19+
CATEGORY: '分類',
20+
SHARE: '分享',
21+
SCAN_QR_CODE: 'QRCode',
22+
URL_COPIED: '連結已複製!',
23+
TABLE_OF_CONTENTS: '目錄',
24+
RELATE_POSTS: '相關文章',
25+
COPYRIGHT: '著作權',
26+
AUTHOR: '作者',
27+
URL: '連結',
28+
ANALYTICS: '分析',
29+
POSTS: '篇文章',
30+
ARTICLE: '文章',
31+
VISITORS: '位訪客',
32+
VIEWS: '次查看',
33+
COPYRIGHT_NOTICE: '本文採用 CC BY-NC-SA 4.0 許可協議,轉載請註明出處。',
34+
RESULT_OF_SEARCH: '篇搜尋到的结果',
35+
ARTICLE_DETAIL: '完整文章',
36+
PASSWORD_ERROR: '密碼錯誤!',
37+
ARTICLE_LOCK_TIPS: '文章已上鎖,請輸入訪問密碼',
38+
SUBMIT: '提交',
39+
POST_TIME: '发布于',
40+
LAST_EDITED_TIME: '最后更新'
941
},
1042
PAGINATION: {
1143
PREV: '上一頁',
1244
NEXT: '下一頁'
1345
},
1446
SEARCH: {
1547
ARTICLES: '搜尋文章',
16-
TAGS: '搜尋標簽'
48+
TAGS: '搜尋標籤'
1749
},
1850
POST: {
1951
BACK: '返回',

lib/lang/zh-TW.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default {
1010
ARCHIVE: '封存'
1111
},
1212
COMMON: {
13+
ARTICLE_LIST: '文章列表',
1314
MORE: '更多',
1415
NO_MORE: '沒有更多了',
1516
LATEST_POSTS: '最新文章',
+20-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
import { useGitBookGlobal } from '@/themes/gitbook'
2-
import JumpToTopButton from './JumpToTopButton'
1+
import MobileButtonCatalog from './MobileButtonCatalog'
2+
import MobileButtonPageNav from './MobileButtonPageNav'
33

4+
/**
5+
* 移动端底部导航
6+
* @param {*} param0
7+
* @returns
8+
*/
49
export default function BottomMenuBar({ post, className }) {
5-
const { pageNavVisible, changePageNavVisible } = useGitBookGlobal()
6-
7-
const togglePageNavVisible = () => {
8-
changePageNavVisible(!pageNavVisible)
9-
}
10+
const showTocButton = post?.toc?.length > 1
1011

1112
return (
12-
<div className={'sticky z-10 bottom-0 w-full h-12 bg-white dark:bg-hexo-black-gray ' + className}>
13-
<div className='flex justify-between h-full shadow-card'>
14-
<div onClick={togglePageNavVisible} className='flex w-full items-center justify-center cursor-pointer'>
15-
<i className="fa-solid fa-book"></i>
16-
</div>
17-
<div className='flex w-full items-center justify-center cursor-pointer'>
18-
<JumpToTopButton />
19-
</div>
20-
</div>
13+
<>
14+
{/* 移动端底部导航按钮 */}
15+
<div className='bottom-button-group md:hidden w-screen h-14 px-4 fixed flex items-center justify-between right-left bottom-0 z-30 bg-white border-t dark:border-gray-800'>
16+
<div className='w-full'>
17+
<MobileButtonPageNav />
2118
</div>
19+
{showTocButton && (
20+
<div className='w-full'>
21+
<MobileButtonCatalog />
22+
</div>
23+
)}
24+
</div>
25+
</>
2226
)
2327
}

themes/gitbook/components/Footer.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { siteConfig } from '@/lib/config'
22
import SocialButton from './SocialButton'
3-
3+
/**
4+
* 站点也叫
5+
* @param {*} param0
6+
* @returns
7+
*/
48
const Footer = ({ siteInfo }) => {
59
const d = new Date()
610
const currentYear = d.getFullYear()

themes/gitbook/components/MobileButtonCatalog.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { useGlobal } from '@/lib/global'
12
import { useGitBookGlobal } from '@/themes/gitbook'
23

34
/**
45
* 移动端目录按钮
56
*/
67
export default function MobileButtonCatalog() {
78
const { tocVisible, changeTocVisible } = useGitBookGlobal()
9+
const { locale } = useGlobal()
810

911
const toggleToc = () => {
1012
changeTocVisible(!tocVisible)
@@ -19,9 +21,11 @@ export default function MobileButtonCatalog() {
1921
<a
2022
id='toc-button'
2123
className={
22-
'fa-list-ol cursor-pointer fas hover:scale-150 transform duration-200'
23-
}
24-
/>
24+
'space-x-4 cursor-pointer hover:scale-150 transform duration-200'
25+
}>
26+
<i className='fa-list-ol fas' />
27+
<span>{locale.COMMON.TABLE_OF_CONTENTS}</span>
28+
</a>
2529
</div>
2630
)
2731
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { useGlobal } from '@/lib/global'
12
import { useGitBookGlobal } from '@/themes/gitbook'
23

34
/**
45
* 移动端文章导航按钮
56
*/
67
export default function MobileButtonPageNav() {
78
const { pageNavVisible, changePageNavVisible } = useGitBookGlobal()
8-
9+
const { locale } = useGlobal()
910
const togglePageNavVisible = () => {
1011
changePageNavVisible(!pageNavVisible)
1112
}
@@ -17,11 +18,13 @@ export default function MobileButtonPageNav() {
1718
'text-black flex justify-center items-center dark:text-gray-200 dark:bg-hexo-black-gray py-2 px-2'
1819
}>
1920
<a
20-
id='toc-button'
21+
id='nav-button'
2122
className={
22-
'fa-book cursor-pointer fas hover:scale-150 transform duration-200'
23-
}
24-
/>
23+
'space-x-4 cursor-pointer hover:scale-150 transform duration-200'
24+
}>
25+
<i className='fa-book fas' />
26+
<span>{locale.COMMON.ARTICLE_LIST}</span>
27+
</a>
2528
</div>
2629
)
2730
}

themes/gitbook/components/PageNavDrawer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const PageNavDrawer = props => {
3434
className={`${pageNavVisible ? 'animate__slideInLeft ' : '-ml-80 animate__slideOutLeft'}
3535
overflow-y-hidden shadow-card w-72 duration-200 fixed left-1 bottom-16 rounded py-2 bg-white dark:bg-hexo-black-gray`}>
3636
<div className='px-4 pb-2 flex justify-between items-center border-b font-bold'>
37-
<span>{locale.COMMON.ARTICLE}</span>
37+
<span>{locale.COMMON.ARTICLE_LIST}</span>
3838
<i
3939
className='fas fa-times p-1 cursor-pointer'
4040
onClick={() => {

0 commit comments

Comments
 (0)