From f1a29575bd28f5dfdb8e26f79a45edeb39bdcce0 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 13 Apr 2022 13:05:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D404=E8=B7=B3=E8=BD=ACbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Comment.js | 3 +++ components/NotionPage.js | 26 +++++++++++++-------- lib/rss.js | 2 +- pages/article/[slug].js | 7 +++--- pages/search/[keyword].js | 7 +++--- themes/example/LayoutSlug.js | 11 ++++++--- themes/fukasawa/components/ArticleDetail.js | 14 +++++++---- themes/hexo/LayoutSlug.js | 11 ++++++++- themes/hexo/components/HeaderArticle.js | 7 ++++-- themes/medium/LayoutSlug.js | 6 +++++ themes/medium/components/ArticleDetail.js | 4 ++-- themes/medium/components/Progress.js | 1 - themes/next/LayoutSlug.js | 8 +++++++ themes/next/components/ArticleDetail.js | 8 +++---- 14 files changed, 78 insertions(+), 37 deletions(-) diff --git a/components/Comment.js b/components/Comment.js index 71c7bc09..45bb554f 100644 --- a/components/Comment.js +++ b/components/Comment.js @@ -26,6 +26,9 @@ const GiscusComponent = dynamic( ) const Comment = ({ frontMatter }) => { + if (!frontMatter) { + return <>Loading... + } const router = useRouter() const { locale, isDarkMode } = useGlobal() return ( diff --git a/components/NotionPage.js b/components/NotionPage.js index 0267571a..ace4fe5b 100644 --- a/components/NotionPage.js +++ b/components/NotionPage.js @@ -37,6 +37,10 @@ const Modal = dynamic( } ) const NotionPage = ({ post }) => { + if (!post || !post.blockMap) { + return <>Loading... + } + const zoom = typeof window !== 'undefined' && mediumZoom({ container: '.notion-viewport', background: 'rgba(0, 0, 0, 0.2)', @@ -57,16 +61,18 @@ const NotionPage = ({ post }) => { } }, [router.events]) - return + return
+ +
} const mapPageUrl = id => { diff --git a/lib/rss.js b/lib/rss.js index 3d75d888..840045ad 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -41,7 +41,7 @@ export async function generateRss(posts) { link: `${BLOG.LINK}/article/${post.slug}`, description: post.summary, content: await createFeedContent(post), - date: new Date(post?.date?.start_date || post.createdTime) + date: new Date(post?.date?.start_date || post?.createdTime) }) } return feed.atom1() diff --git a/pages/article/[slug].js b/pages/article/[slug].js index 09259f7f..b190738d 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -24,19 +24,18 @@ const Slug = props => { const article = document.getElementById('container') if (!article) { router.push('/404').then(() => { - console.log('找不到页面', router.asPath) + console.warn('找不到页面', router.asPath) }) } } }, 3000) }) - - return

Redirecting...

+ const meta = { title: `${props?.siteInfo?.title} | loading` } + return } // 文章锁🔐 const [lock, setLock] = useState(post.password && post.password !== '') - console.log('lock 默认值', lock) useEffect(() => { if (post.password && post.password !== '') { setLock(true) diff --git a/pages/search/[keyword].js b/pages/search/[keyword].js index 1308726e..a45ae9bf 100644 --- a/pages/search/[keyword].js +++ b/pages/search/[keyword].js @@ -7,9 +7,8 @@ const Index = props => { const { keyword, siteInfo } = props const { locale } = useGlobal() const meta = { - title: `${keyword || ''}${keyword ? ' | ' : ''}${locale.NAV.SEARCH} | ${ - siteInfo.title - }`, + title: `${keyword || ''}${keyword ? ' | ' : ''}${locale.NAV.SEARCH} | ${siteInfo.title + }`, description: siteInfo.title, slug: 'search/' + (keyword || ''), type: 'website' @@ -111,7 +110,7 @@ async function filterByMemCache(allPosts, keyword) { indexContent = appendText(indexContent, properties, 'caption') }) } - // console.log('搜索是否命中缓存', page !== null, indexContent) + console.log('搜索是否命中缓存', page !== null, indexContent) post.results = [] let hitCount = 0 for (const i in indexContent) { diff --git a/themes/example/LayoutSlug.js b/themes/example/LayoutSlug.js index 70482b5d..91b11d80 100644 --- a/themes/example/LayoutSlug.js +++ b/themes/example/LayoutSlug.js @@ -8,13 +8,18 @@ import formatDate from '@/lib/formatDate' export const LayoutSlug = props => { const { post, lock, validPassword } = props + + if (!post) { + return + } + if (!lock && post?.blockMap?.block) { post.content = Object.keys(post.blockMap.block) post.toc = getPageTableOfContents(post, post.blockMap) } const { locale } = useGlobal() - const date = formatDate(post?.date?.start_date || post.createdTime, locale.LOCALE) + const date = formatDate(post?.date?.start_date || post?.createdTime, locale.LOCALE) return ( @@ -34,7 +39,7 @@ export const LayoutSlug = props => { | - {post.type[0] !== 'Page' && (<> + {post?.type[0] !== 'Page' && (<> { - {post.blockMap && } + {post && } } diff --git a/themes/fukasawa/components/ArticleDetail.js b/themes/fukasawa/components/ArticleDetail.js index cbdfa0b7..77271f5f 100644 --- a/themes/fukasawa/components/ArticleDetail.js +++ b/themes/fukasawa/components/ArticleDetail.js @@ -10,11 +10,15 @@ import ArticleAround from './ArticleAround' * @param {*} param0 * @returns */ -export default function ArticleDetail({ post, recommendPosts, prev, next }) { +export default function ArticleDetail(props) { + const { post, prev, next } = props + if (!post) { + return <> + } const { locale } = useGlobal() - const date = formatDate(post?.date?.start_date || post.createdTime, locale.LOCALE) + const date = formatDate(post?.date?.start_date || post?.createdTime, locale.LOCALE) return (
- {post.type && !post.type.includes('Page') && post?.page_cover && ( + {post?.type && !post?.type.includes('Page') && post?.page_cover && (
{/* eslint-disable-next-line @next/next/no-img-element */} {post.title} @@ -41,7 +45,7 @@ export default function ArticleDetail({ post, recommendPosts, prev, next }) { | - {post.type[0] !== 'Page' && (<> + {post?.type[0] !== 'Page' && (<> - {post.blockMap && } + {post && }
diff --git a/themes/hexo/LayoutSlug.js b/themes/hexo/LayoutSlug.js index e2fec724..ee3143cf 100644 --- a/themes/hexo/LayoutSlug.js +++ b/themes/hexo/LayoutSlug.js @@ -15,6 +15,15 @@ import ArticleRecommend from './components/ArticleRecommend' export const LayoutSlug = props => { const { post, lock, validPassword } = props + if (!post) { + return } + {...props} + showCategory={false} + showTag={false} + > + } + if (!lock && post?.blockMap?.block) { post.content = Object.keys(post.blockMap.block) post.toc = getPageTableOfContents(post, post.blockMap) @@ -50,7 +59,7 @@ export const LayoutSlug = props => {
{/* Notion文章主体 */}
- {post.blockMap && } + {post && }
diff --git a/themes/hexo/components/HeaderArticle.js b/themes/hexo/components/HeaderArticle.js index 3e91179d..bd0bea4a 100644 --- a/themes/hexo/components/HeaderArticle.js +++ b/themes/hexo/components/HeaderArticle.js @@ -4,12 +4,15 @@ import formatDate from '@/lib/formatDate' import { useEffect } from 'react' export default function HeaderArticle({ post, siteInfo }) { + if (!post) { + return <>loading... + } const headerImage = post?.page_cover ? `url("${post.page_cover}")` : `url("${siteInfo?.pageCover}")` const { isDarkMode } = useGlobal() const { locale } = useGlobal() const date = formatDate( - post?.date?.start_date || post.createdTime, + post?.date?.start_date || post?.createdTime, locale.LOCALE ) @@ -71,7 +74,7 @@ export default function HeaderArticle({ post, siteInfo }) { }
- {post.type[0] !== 'Page' && ( + {post?.type[0] !== 'Page' && ( <> { const { post, lock, validPassword } = props + if (!post) { + return + } if (!lock && post?.blockMap?.block) { post.content = Object.keys(post.blockMap.block) diff --git a/themes/medium/components/ArticleDetail.js b/themes/medium/components/ArticleDetail.js index a0ed321e..ddaa9a76 100644 --- a/themes/medium/components/ArticleDetail.js +++ b/themes/medium/components/ArticleDetail.js @@ -15,7 +15,7 @@ export const ArticleDetail = props => { const { locale } = useGlobal() const date = formatDate( - post?.date?.start_date || post.createdTime, + post?.date?.start_date || post?.createdTime, locale.LOCALE ) return
@@ -48,7 +48,7 @@ export const ArticleDetail = props => { {/* Notion文章主体 */}
- {post.blockMap && ()} + {post && ()}
diff --git a/themes/medium/components/Progress.js b/themes/medium/components/Progress.js index 3680e157..d9a13ad9 100644 --- a/themes/medium/components/Progress.js +++ b/themes/medium/components/Progress.js @@ -10,7 +10,6 @@ const Progress = ({ targetRef, showPercent = true }) => { const [percent, changePercent] = useState(0) const scrollListener = () => { const target = currentRef || document.getElementById('container') - console.log(target) if (target) { const clientHeight = target.clientHeight const scrollY = window.pageYOffset diff --git a/themes/next/LayoutSlug.js b/themes/next/LayoutSlug.js index 097f457b..8e7ddd72 100644 --- a/themes/next/LayoutSlug.js +++ b/themes/next/LayoutSlug.js @@ -11,6 +11,14 @@ import { ArticleLock } from './components/ArticleLock' export const LayoutSlug = (props) => { const { post, latestPosts, lock, validPassword } = props + if (!post) { + return + } + /> + } if (!lock && post?.blockMap?.block) { post.content = Object.keys(post.blockMap.block) diff --git a/themes/next/components/ArticleDetail.js b/themes/next/components/ArticleDetail.js index 094b6b22..ab7f9608 100644 --- a/themes/next/components/ArticleDetail.js +++ b/themes/next/components/ArticleDetail.js @@ -21,7 +21,7 @@ export default function ArticleDetail(props) { const { post, recommendPosts, prev, next, showArticleInfo } = props const url = BLOG.LINK + useRouter().asPath const { locale } = useGlobal() - const date = formatDate(post?.date?.start_date || post.createdTime, locale.LOCALE) + const date = formatDate(post?.date?.start_date || post?.createdTime, locale.LOCALE) return (
{showArticleInfo &&
- {post.type && !post.type.includes('Page') && post?.page_cover && ( + {post?.type && !post?.type.includes('Page') && post?.page_cover && (
{/* eslint-disable-next-line @next/next/no-img-element */} {post.title} @@ -51,7 +51,7 @@ export default function ArticleDetail(props) { | } - {post.type[0] !== 'Page' && (<> + {post?.type[0] !== 'Page' && (<> - {post.blockMap && ()} + {post && ()}