mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
修复404跳转bug
This commit is contained in:
@@ -26,6 +26,9 @@ const GiscusComponent = dynamic(
|
||||
)
|
||||
|
||||
const Comment = ({ frontMatter }) => {
|
||||
if (!frontMatter) {
|
||||
return <>Loading...</>
|
||||
}
|
||||
const router = useRouter()
|
||||
const { locale, isDarkMode } = useGlobal()
|
||||
return (
|
||||
|
||||
@@ -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 <NotionRenderer
|
||||
recordMap={post.blockMap}
|
||||
mapPageUrl={mapPageUrl}
|
||||
components={{
|
||||
Code,
|
||||
Collection,
|
||||
Equation,
|
||||
Modal,
|
||||
Pdf
|
||||
}} />
|
||||
return <div id='container'>
|
||||
<NotionRenderer
|
||||
recordMap={post.blockMap}
|
||||
mapPageUrl={mapPageUrl}
|
||||
components={{
|
||||
Code,
|
||||
Collection,
|
||||
Equation,
|
||||
Modal,
|
||||
Pdf
|
||||
}} />
|
||||
</div>
|
||||
}
|
||||
|
||||
const mapPageUrl = id => {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 <p>Redirecting...</p>
|
||||
const meta = { title: `${props?.siteInfo?.title} | loading` }
|
||||
return <ThemeComponents.LayoutSlug {...props} showArticleInfo={true} meta={meta} />
|
||||
}
|
||||
|
||||
// 文章锁🔐
|
||||
const [lock, setLock] = useState(post.password && post.password !== '')
|
||||
console.log('lock 默认值', lock)
|
||||
useEffect(() => {
|
||||
if (post.password && post.password !== '') {
|
||||
setLock(true)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -8,13 +8,18 @@ import formatDate from '@/lib/formatDate'
|
||||
|
||||
export const LayoutSlug = props => {
|
||||
const { post, lock, validPassword } = props
|
||||
|
||||
if (!post) {
|
||||
return <LayoutBase {...props} />
|
||||
}
|
||||
|
||||
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 (
|
||||
<LayoutBase {...props}>
|
||||
@@ -34,7 +39,7 @@ export const LayoutSlug = props => {
|
||||
</Link>
|
||||
<span className='mr-2'>|</span>
|
||||
|
||||
{post.type[0] !== 'Page' && (<>
|
||||
{post?.type[0] !== 'Page' && (<>
|
||||
<Link
|
||||
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
|
||||
passHref
|
||||
@@ -60,7 +65,7 @@ export const LayoutSlug = props => {
|
||||
|
||||
</section>
|
||||
|
||||
{post.blockMap && <NotionPage post={post} />}
|
||||
{post && <NotionPage post={post} />}
|
||||
</section>}
|
||||
|
||||
</div>
|
||||
|
||||
@@ -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 (<div id="container" className="max-w-5xl overflow-x-auto flex-grow mx-auto w-screen md:w-full ">
|
||||
{post.type && !post.type.includes('Page') && post?.page_cover && (
|
||||
{post?.type && !post?.type.includes('Page') && post?.page_cover && (
|
||||
<div className="w-full relative md:flex-shrink-0 overflow-hidden">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img alt={post.title} src={post?.page_cover} className='object-center w-full' />
|
||||
@@ -41,7 +45,7 @@ export default function ArticleDetail({ post, recommendPosts, prev, next }) {
|
||||
</Link>
|
||||
<span className='mr-2'>|</span>
|
||||
|
||||
{post.type[0] !== 'Page' && (<>
|
||||
{post?.type[0] !== 'Page' && (<>
|
||||
<Link
|
||||
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
|
||||
passHref
|
||||
@@ -69,7 +73,7 @@ export default function ArticleDetail({ post, recommendPosts, prev, next }) {
|
||||
|
||||
{/* Notion文章主体 */}
|
||||
<section id='notion-article' className='px-1'>
|
||||
{post.blockMap && <NotionPage post={post} />}
|
||||
{post && <NotionPage post={post} />}
|
||||
</section>
|
||||
|
||||
<section className="px-1 py-2 my-1 text-sm font-light overflow-auto text-gray-600 dark:text-gray-400">
|
||||
|
||||
@@ -15,6 +15,15 @@ import ArticleRecommend from './components/ArticleRecommend'
|
||||
export const LayoutSlug = props => {
|
||||
const { post, lock, validPassword } = props
|
||||
|
||||
if (!post) {
|
||||
return <LayoutBase
|
||||
headerSlot={<HeaderArticle {...props} />}
|
||||
{...props}
|
||||
showCategory={false}
|
||||
showTag={false}
|
||||
></LayoutBase>
|
||||
}
|
||||
|
||||
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 => {
|
||||
<article itemScope itemType="https://schema.org/Movie" className="subpixel-antialiased" >
|
||||
{/* Notion文章主体 */}
|
||||
<section id='notion-article' className='px-5'>
|
||||
{post.blockMap && <NotionPage post={post} />}
|
||||
{post && <NotionPage post={post} />}
|
||||
</section>
|
||||
|
||||
<section className="px-1 py-2 my-1 text-sm font-light overflow-auto text-gray-600 dark:text-gray-400">
|
||||
|
||||
@@ -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 }) {
|
||||
</>}
|
||||
</div>
|
||||
<div className='flex justify-center'>
|
||||
{post.type[0] !== 'Page' && (
|
||||
{post?.type[0] !== 'Page' && (
|
||||
<>
|
||||
<Link
|
||||
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
|
||||
|
||||
@@ -9,6 +9,12 @@ import { ArticleLock } from './components/ArticleLock'
|
||||
|
||||
export const LayoutSlug = props => {
|
||||
const { post, lock, validPassword } = props
|
||||
if (!post) {
|
||||
return <LayoutBase
|
||||
{...props}
|
||||
showInfoCard={true}
|
||||
/>
|
||||
}
|
||||
|
||||
if (!lock && post?.blockMap?.block) {
|
||||
post.content = Object.keys(post.blockMap.block)
|
||||
|
||||
@@ -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 <div id='container'>
|
||||
@@ -48,7 +48,7 @@ export const ArticleDetail = props => {
|
||||
</section>
|
||||
{/* Notion文章主体 */}
|
||||
<section id="notion-article" className="px-1 max-w-5xl">
|
||||
{post.blockMap && (<NotionPage post={post} />)}
|
||||
{post && (<NotionPage post={post} />)}
|
||||
</section>
|
||||
|
||||
<section className="px-1 py-2 my-1 text-sm font-light overflow-auto text-gray-600 dark:text-gray-400">
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -11,6 +11,14 @@ import { ArticleLock } from './components/ArticleLock'
|
||||
|
||||
export const LayoutSlug = (props) => {
|
||||
const { post, latestPosts, lock, validPassword } = props
|
||||
if (!post) {
|
||||
return <LayoutBase
|
||||
{...props}
|
||||
rightAreaSlot={
|
||||
CONFIG_NEXT.RIGHT_LATEST_POSTS && <Card><LatestPostsGroup posts={latestPosts} /></Card>
|
||||
}
|
||||
/>
|
||||
}
|
||||
|
||||
if (!lock && post?.blockMap?.block) {
|
||||
post.content = Object.keys(post.blockMap.block)
|
||||
|
||||
@@ -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 (<div id="container" className="shadow md:hover:shadow-2xl overflow-x-auto flex-grow mx-auto w-screen md:w-full ">
|
||||
<div itemScope itemType="https://schema.org/Movie"
|
||||
@@ -29,7 +29,7 @@ export default function ArticleDetail(props) {
|
||||
>
|
||||
|
||||
{showArticleInfo && <header className='animate__slideInDown animate__animated'>
|
||||
{post.type && !post.type.includes('Page') && post?.page_cover && (
|
||||
{post?.type && !post?.type.includes('Page') && post?.page_cover && (
|
||||
<div className="w-full relative md:flex-shrink-0 overflow-hidden">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img alt={post.title} src={post?.page_cover} className='object-center w-full' />
|
||||
@@ -51,7 +51,7 @@ export default function ArticleDetail(props) {
|
||||
</Link>
|
||||
<span className='mr-2'>|</span>
|
||||
</>}
|
||||
{post.type[0] !== 'Page' && (<>
|
||||
{post?.type[0] !== 'Page' && (<>
|
||||
<Link
|
||||
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
|
||||
passHref
|
||||
@@ -84,7 +84,7 @@ export default function ArticleDetail(props) {
|
||||
|
||||
{/* Notion内容主体 */}
|
||||
<article id='notion-article' className='px-1'>
|
||||
{post.blockMap && (<NotionPage post={post} />)}
|
||||
{post && (<NotionPage post={post} />)}
|
||||
</article>
|
||||
|
||||
<section className="px-1 py-2 my-1 text-sm font-light overflow-auto text-gray-600 dark:text-gray-400">
|
||||
|
||||
Reference in New Issue
Block a user