Merge branch 'preview' into main

This commit is contained in:
tangly1024
2022-03-16 12:21:36 +08:00
3 changed files with 23 additions and 5 deletions

View File

@@ -17,9 +17,7 @@ export function GlobalContextProvider ({ children }) {
const [locale, updateLocale] = useState(generateLocaleDict('en-US'))
const [isDarkMode, updateDarkMode] = useState(false)
const [onLoading, changeLoadingState] = useState(false)
// 会优先读取浏览器中的主题参数
const [theme, setTheme] = useState(Router?.router?.query?.theme || BLOG.THEME)
const [theme, setTheme] = useState(BLOG.THEME)
Router.events.on('routeChangeStart', (...args) => {
changeLoadingState(true)
})
@@ -30,6 +28,11 @@ export function GlobalContextProvider ({ children }) {
useEffect(() => {
if (!hasInit) {
const userTheme = getQueryVariable('theme')
console.log('用户主题', userTheme)
if (userTheme && ALL_THEME.indexOf(userTheme) > -1) {
setTheme(userTheme)
}
initLocale(locale, updateLocale)
initDarkMode(isDarkMode, updateDarkMode)
hasInit = true
@@ -43,6 +46,21 @@ export function GlobalContextProvider ({ children }) {
)
}
/**
* 查询url中的query参数
* @param {}} variable
* @returns
*/
function getQueryVariable (variable) {
const query = window.location.search.substring(1)
const vars = query.split('&')
for (let i = 0; i < vars.length; i++) {
const pair = vars[i].split('=')
if (pair[0] === variable) { return pair[1] }
}
return (false)
}
/**
* 深度合并两个对象
* @param target

View File

@@ -4,7 +4,7 @@ import Link from 'next/link'
export default function LogoBar () {
return <div id='top-wrapper' className='w-full flex items-center font-sans'>
<Link href='/'>
<a className='text-2xl dark:text-gray-200'>{BLOG.TITLE}</a>
<a className='text-md md:text-xl dark:text-gray-200'>{BLOG.TITLE}</a>
</Link>
</div>
}

View File

@@ -21,7 +21,7 @@ export default function TopNavBar (props) {
if (link.show) {
const selected = (router.pathname === link.to) || (router.asPath === link.to)
return <Link key={`${link.id}-${link.to}`} title={link.to} href={link.to} >
<a className={'px-2 duration-300 text-base justify-between dark:text-gray-300 hover:underline cursor-pointer flex flex-nowrap items-center ' +
<a className={'px-2 duration-300 text-sm justify-between dark:text-gray-300 hover:underline cursor-pointer flex flex-nowrap items-center ' +
(selected ? 'bg-green-600 text-white hover:text-white' : 'hover:text-green-600')} >
<div className='items-center justify-center flex '>
<i className={link.icon} />