layout优化,图片优化
This commit is contained in:
tangly1024
2021-12-23 14:59:38 +08:00
parent e8ca3cb754
commit 2c07a79d1e
4 changed files with 23 additions and 28 deletions

View File

@@ -1,7 +1,6 @@
import CommonHead from '@/components/CommonHead' import CommonHead from '@/components/CommonHead'
import FloatDarkModeButton from '@/components/FloatDarkModeButton' import FloatDarkModeButton from '@/components/FloatDarkModeButton'
import Footer from '@/components/Footer' import Footer from '@/components/Footer'
import Header from '@/components/Header'
import JumpToBottomButton from '@/components/JumpToBottomButton' import JumpToBottomButton from '@/components/JumpToBottomButton'
import JumpToTopButton from '@/components/JumpToTopButton' import JumpToTopButton from '@/components/JumpToTopButton'
import LoadingCover from '@/components/LoadingCover' import LoadingCover from '@/components/LoadingCover'
@@ -9,7 +8,6 @@ import SideAreaRight from '@/components/SideAreaRight'
import TopNav from '@/components/TopNav' import TopNav from '@/components/TopNav'
import { useGlobal } from '@/lib/global' import { useGlobal } from '@/lib/global'
import throttle from 'lodash.throttle' import throttle from 'lodash.throttle'
import { useRouter } from 'next/router'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import React, { useCallback, useEffect, useRef } from 'react' import React, { useCallback, useEffect, useRef } from 'react'
/** /**
@@ -33,6 +31,7 @@ const BaseLayout = ({
children, children,
layout, layout,
fullWidth, fullWidth,
headerSlot,
tags, tags,
meta, meta,
post, post,
@@ -65,40 +64,29 @@ const BaseLayout = ({
}, []) }, [])
const { onLoading } = useGlobal() const { onLoading } = useGlobal()
const targetRef = useRef(null) const targetRef = useRef(null)
const router = useRouter() console.log('header', headerSlot)
return (<> return (<>
<CommonHead meta={meta} /> <CommonHead meta={meta} />
{/* 顶部导航栏 */} <TopNav tags={tags} post={post} posts={totalPosts} currentSearch={currentSearch} categories={categories} currentCategory={currentCategory} />
{/* {router.asPath === '/as' && */}
<TopNav tags={tags} post={post} posts={totalPosts} currentSearch={currentSearch} categories={categories} currentCategory={currentCategory} />
{/* } */}
{/* 首页头图 */} <>{headerSlot}</>
{router.asPath === '/' && <Header/>}
<div id='wrapper' className='flex justify-center flex-1 mx-auto md:pt-8 pb-12'> <main id='wrapper' className='flex justify-center flex-1 mx-auto md:pt-8 pb-12'>
<section id='center' className='flex-grow max-w-4xl min-h-screen md:mx-10' ref={targetRef}>
{/* <div id='left' className='hidden lg:block flex-col w-72'>
<SideAreaLeft targetRef={targetRef} title={meta.title} post={post} posts={totalPosts} tags={tags} currentSearch={currentSearch} currentTag={currentTag} categories={categories} currentCategory={currentCategory} />
</div> */}
<div id='center' className='flex-grow max-w-4xl min-h-screen md:mx-10' ref={targetRef}>
{onLoading {onLoading
? <LoadingCover/> ? <LoadingCover/>
: <> : <>
{children} {children}
</> </>
} }
</div> </section>
<aside id='right' className='hidden lg:block flex-col w-72 mr-5'>
<div id='right' className='hidden lg:block flex-col w-72 mr-5'>
<SideAreaRight targetRef={targetRef} post={post} posts={totalPosts} tags={tags} currentSearch={currentSearch} currentTag={currentTag} categories={categories} currentCategory={currentCategory}/> <SideAreaRight targetRef={targetRef} post={post} posts={totalPosts} tags={tags} currentSearch={currentSearch} currentTag={currentTag} categories={categories} currentCategory={currentCategory}/>
</div> </aside>
</main>
</div>
<Footer title={meta.title}/> <Footer title={meta.title}/>
<JumpToTopButton targetRef={targetRef} showPercent={false} /> <JumpToTopButton targetRef={targetRef} showPercent={false} />

View File

@@ -1,5 +1,5 @@
import { getCacheFromMemory, setCacheToMemory } from '@/lib/cache/memory_cache' // import { getCacheFromMemory, setCacheToMemory } from '@/lib/cache/memory_cache'
// import { getCacheFromFile, setCacheToFile } from './local_file_cache' import { getCacheFromFile, setCacheToFile } from './local_file_cache'
const enableCache = true // 生产环境禁用 const enableCache = true // 生产环境禁用
/** /**
@@ -11,7 +11,7 @@ export async function getDataFromCache (key) {
if (!enableCache) { if (!enableCache) {
return null return null
} }
const dataFromCache = await getCacheFromMemory(key) const dataFromCache = await getCacheFromFile(key)
if (JSON.stringify(dataFromCache) === '[]') { if (JSON.stringify(dataFromCache) === '[]') {
return null return null
} }
@@ -22,5 +22,5 @@ export async function setDataToCache (key, data) {
if (!enableCache || !data) { if (!enableCache || !data) {
return return
} }
await setCacheToMemory(key, data) await setCacheToFile(key, data)
} }

View File

@@ -3,6 +3,7 @@ import BLOG from '@/blog.config'
import BaseLayout from '@/layouts/BaseLayout' import BaseLayout from '@/layouts/BaseLayout'
import BlogPostListScroll from '@/components/BlogPostListScroll' import BlogPostListScroll from '@/components/BlogPostListScroll'
import { getNotionPageData } from '@/lib/notion/getNotionData' import { getNotionPageData } from '@/lib/notion/getNotionData'
import Header from '@/components/Header'
export async function getStaticProps () { export async function getStaticProps () {
const from = 'index' const from = 'index'
@@ -29,8 +30,14 @@ export async function getStaticProps () {
const Index = ({ allPosts, tags, meta, categories }) => { const Index = ({ allPosts, tags, meta, categories }) => {
return ( return (
<BaseLayout meta={meta} tags={tags} totalPosts={allPosts} categories={categories}> <BaseLayout
<BlogPostListScroll posts={allPosts} tags={tags} /> headerSlot={<Header />}
meta={meta}
tags={tags}
totalPosts={allPosts}
categories={categories}
>
<BlogPostListScroll posts={allPosts} tags={tags} />
</BaseLayout> </BaseLayout>
) )
} }

BIN
public/bg_image.jpg Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 538 KiB

After

Width:  |  Height:  |  Size: 289 KiB