theme 加载优化

This commit is contained in:
tangly1024.com
2024-01-30 12:50:13 +08:00
parent 7b56f15d4d
commit b415446aa6
12 changed files with 185 additions and 241 deletions

View File

@@ -46,8 +46,11 @@ export const useHexoGlobal = () => useContext(ThemeGlobalHexo)
* @constructor
*/
const LayoutBase = props => {
const { children, headerSlot, floatSlot, slotTop, meta, className } = props
const { children, floatSlot, slotTop, meta, className } = props
const { onLoading, fullWidth } = useGlobal()
const router = useRouter()
const headerSlot = router.route==='/' && siteConfig('HEXO_HOME_BANNER_ENABLE', null, CONFIG) ? <Hero {...props} /> : null
// Algolia搜索框
const searchModal = useRef(null)
@@ -125,8 +128,7 @@ const LayoutBase = props => {
* @returns
*/
const LayoutIndex = (props) => {
const headerSlot = siteConfig('HEXO_HOME_BANNER_ENABLE', null, CONFIG) && <Hero {...props} />
return <LayoutPostList {...props} headerSlot={headerSlot} className='pt-8' />
return <LayoutPostList {...props} className='pt-8' />
}
/**
@@ -135,10 +137,10 @@ const LayoutIndex = (props) => {
* @returns
*/
const LayoutPostList = (props) => {
return <LayoutBase {...props} className='pt-8'>
return <div {...props} className='pt-8'>
<SlotBar {...props} />
{siteConfig('POST_LIST_STYLE') === 'page' ? <BlogPostListPage {...props} /> : <BlogPostListScroll {...props} />}
</LayoutBase>
</div>
}
/**
@@ -165,11 +167,11 @@ const LayoutSearch = props => {
})
return (
<LayoutBase {...props} currentSearch={currentSearch} className='pt-8'>
<div {...props} currentSearch={currentSearch} className='pt-8'>
{!currentSearch
? <SearchNav {...props} />
: <div id="posts-wrapper"> {siteConfig('POST_LIST_STYLE') === 'page' ? <BlogPostListPage {...props} /> : <BlogPostListScroll {...props} />} </div>}
</LayoutBase>
</div>
)
}
@@ -180,7 +182,7 @@ const LayoutSearch = props => {
*/
const LayoutArchive = (props) => {
const { archivePosts } = props
return <LayoutBase {...props} className='pt-8'>
return <div {...props} className='pt-8'>
<Card className='w-full'>
<div className="mb-10 pb-20 bg-white md:p-12 p-3 min-h-full dark:bg-hexo-black-gray">
{Object.keys(archivePosts).map(archiveTitle => (
@@ -192,7 +194,7 @@ const LayoutArchive = (props) => {
))}
</div>
</Card>
</LayoutBase>
</div>
}
/**
@@ -218,7 +220,7 @@ const LayoutSlug = props => {
</>
return (
<LayoutBase {...props} headerSlot={<PostHeader {...props} />} showCategory={false} showTag={false} floatSlot={floatSlot} >
<div {...props} headerSlot={<PostHeader {...props} />} showCategory={false} showTag={false} floatSlot={floatSlot} >
<div className="w-full lg:hover:shadow lg:border rounded-t-xl lg:rounded-xl lg:px-2 lg:py-4 bg-white dark:bg-hexo-black-gray dark:border-black article">
{lock && <ArticleLock validPassword={validPassword} />}
@@ -253,7 +255,7 @@ const LayoutSlug = props => {
<TocDrawer post={post} cRef={drawerRight} targetRef={targetRef} />
</div>
</LayoutBase>
</div>
)
}
@@ -278,7 +280,7 @@ const Layout404 = props => {
}, 3000)
})
return (
<LayoutBase {...props}>
<div {...props}>
<div className="text-black w-full h-screen text-center justify-center content-center items-center flex flex-col">
<div className="dark:text-gray-200">
<h2 className="inline-block border-r-2 border-gray-600 mr-2 px-3 py-2 align-top">
@@ -289,7 +291,7 @@ const Layout404 = props => {
</div>
</div>
</div>
</LayoutBase>
</div>
)
}
@@ -302,7 +304,7 @@ const LayoutCategoryIndex = props => {
const { categoryOptions } = props
const { locale } = useGlobal()
return (
<LayoutBase {...props} className='mt-8'>
<div {...props} className='mt-8'>
<Card className="w-full min-h-screen">
<div className="dark:text-gray-200 mb-5 mx-3">
<i className="mr-4 fas fa-th" /> {locale.COMMON.CATEGORY}:
@@ -319,7 +321,7 @@ const LayoutCategoryIndex = props => {
})}
</div>
</Card>
</LayoutBase>
</div>
)
}
@@ -332,7 +334,7 @@ const LayoutTagIndex = props => {
const { tagOptions } = props
const { locale } = useGlobal()
return (
<LayoutBase {...props} className='mt-8'>
<div {...props} className='mt-8'>
<Card className='w-full'>
<div className="dark:text-gray-200 mb-5 ml-4">
<i className="mr-4 fas fa-tag" /> {locale.COMMON.TAGS}:
@@ -343,12 +345,13 @@ const LayoutTagIndex = props => {
</div>)}
</div>
</Card>
</LayoutBase>
</div>
)
}
export {
CONFIG as THEME_CONFIG,
LayoutBase,
LayoutIndex,
LayoutSearch,
LayoutArchive,