starter主题新增lite模式,隐藏页头页脚便于嵌入

This commit is contained in:
tangly1024
2025-07-11 17:29:38 +08:00
parent 5e6fa26c90
commit b2c9ed5014
2 changed files with 42 additions and 22 deletions

View File

@@ -31,6 +31,7 @@ export function GlobalContextProvider(props) {
) // 默认语言
const [theme, setTheme] = useState(NOTION_CONFIG?.THEME || THEME) // 默认博客主题
const [THEME_CONFIG, SET_THEME_CONFIG] = useState(null) // 主题配置
const [isLiteMode,setLiteMode] = useState(false)
const defaultDarkMode = NOTION_CONFIG?.APPEARANCE || APPEARANCE
const [isDarkMode, updateDarkMode] = useState(defaultDarkMode === 'dark') // 默认深色模式
@@ -107,6 +108,9 @@ export function GlobalContextProvider(props) {
const newUrl = `${url}${url.includes('?') ? '&' : '?'}theme=${themeStr}`
router.push(newUrl)
}
if (router.query.lite && router.query.lite==='true') {
setLiteMode(true)
}
if (!onLoading) {
setOnLoading(true)
}
@@ -134,6 +138,7 @@ export function GlobalContextProvider(props) {
return (
<GlobalContext.Provider
value={{
isLiteMode,
isLoaded,
isSignedIn,
user,

View File

@@ -50,34 +50,49 @@ import { SVG404 } from './components/svg/SVG404'
* @returns
*/
const LayoutBase = props => {
const { children } = props
const { children } = props
// 极简模式,会隐藏掉页头页脚等组件,便于嵌入网页等功能
const { isLiteMode } = useGlobal()
const router = useRouter()
// 加载wow动画
useEffect(() => {
loadWowJS()
}, [])
// 加载wow动画
useEffect(() => {
loadWowJS()
}, [])
return (
<div
id='theme-starter'
className={`${siteConfig('FONT_STYLE')} min-h-screen flex flex-col dark:bg-[#212b36] scroll-smooth`}>
<Style />
{/* 页头 */}
<Header {...props} />
// 特殊简化布局,如果识别到路由中有 ?lite=true则给网页添加一些自定义的css样式例如背景改成黑色
useEffect(() => {
const isLiteMode = router.query.lite === 'true'
console.log(router.query.lite, isLiteMode)
if (isLiteMode) {
document.body.style.backgroundColor = 'black'
document.body.style.color = 'white'
}
}, [])
<div id='main-wrapper' className='grow'>
{children}
</div>
return (
<div
id='theme-starter'
className={`${siteConfig('FONT_STYLE')} min-h-screen flex flex-col dark:bg-[#212b36] scroll-smooth`}>
<Style />
{/* 页 */}
<Footer {...props} />
{/* 页 */}
{isLiteMode ? <></> : <Header {...props} />}
{/* 悬浮按钮 */}
<BackToTopButton />
<div id='main-wrapper' className='grow'>
{children}
</div>
{/* <MadeWithButton/> */}
</div>
)
{/* 页脚 */}
{isLiteMode ? <></> : <Footer {...props} />}
{/* 悬浮按钮 */}
{isLiteMode ? <></> : <BackToTopButton />}
{/* <MadeWithButton/> */}
</div>
)
}
/**