mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-04 23:16:53 +00:00
修复404跳转bug
This commit is contained in:
@@ -26,6 +26,9 @@ const GiscusComponent = dynamic(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const Comment = ({ frontMatter }) => {
|
const Comment = ({ frontMatter }) => {
|
||||||
|
if (!frontMatter) {
|
||||||
|
return <>Loading...</>
|
||||||
|
}
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { locale, isDarkMode } = useGlobal()
|
const { locale, isDarkMode } = useGlobal()
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ const Modal = dynamic(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
const NotionPage = ({ post }) => {
|
const NotionPage = ({ post }) => {
|
||||||
|
if (!post || !post.blockMap) {
|
||||||
|
return <>Loading...</>
|
||||||
|
}
|
||||||
|
|
||||||
const zoom = typeof window !== 'undefined' && mediumZoom({
|
const zoom = typeof window !== 'undefined' && mediumZoom({
|
||||||
container: '.notion-viewport',
|
container: '.notion-viewport',
|
||||||
background: 'rgba(0, 0, 0, 0.2)',
|
background: 'rgba(0, 0, 0, 0.2)',
|
||||||
@@ -57,16 +61,18 @@ const NotionPage = ({ post }) => {
|
|||||||
}
|
}
|
||||||
}, [router.events])
|
}, [router.events])
|
||||||
|
|
||||||
return <NotionRenderer
|
return <div id='container'>
|
||||||
recordMap={post.blockMap}
|
<NotionRenderer
|
||||||
mapPageUrl={mapPageUrl}
|
recordMap={post.blockMap}
|
||||||
components={{
|
mapPageUrl={mapPageUrl}
|
||||||
Code,
|
components={{
|
||||||
Collection,
|
Code,
|
||||||
Equation,
|
Collection,
|
||||||
Modal,
|
Equation,
|
||||||
Pdf
|
Modal,
|
||||||
}} />
|
Pdf
|
||||||
|
}} />
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapPageUrl = id => {
|
const mapPageUrl = id => {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export async function generateRss(posts) {
|
|||||||
link: `${BLOG.LINK}/article/${post.slug}`,
|
link: `${BLOG.LINK}/article/${post.slug}`,
|
||||||
description: post.summary,
|
description: post.summary,
|
||||||
content: await createFeedContent(post),
|
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()
|
return feed.atom1()
|
||||||
|
|||||||
@@ -24,19 +24,18 @@ const Slug = props => {
|
|||||||
const article = document.getElementById('container')
|
const article = document.getElementById('container')
|
||||||
if (!article) {
|
if (!article) {
|
||||||
router.push('/404').then(() => {
|
router.push('/404').then(() => {
|
||||||
console.log('找不到页面', router.asPath)
|
console.warn('找不到页面', router.asPath)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 3000)
|
}, 3000)
|
||||||
})
|
})
|
||||||
|
const meta = { title: `${props?.siteInfo?.title} | loading` }
|
||||||
return <p>Redirecting...</p>
|
return <ThemeComponents.LayoutSlug {...props} showArticleInfo={true} meta={meta} />
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文章锁🔐
|
// 文章锁🔐
|
||||||
const [lock, setLock] = useState(post.password && post.password !== '')
|
const [lock, setLock] = useState(post.password && post.password !== '')
|
||||||
console.log('lock 默认值', lock)
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (post.password && post.password !== '') {
|
if (post.password && post.password !== '') {
|
||||||
setLock(true)
|
setLock(true)
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ const Index = props => {
|
|||||||
const { keyword, siteInfo } = props
|
const { keyword, siteInfo } = props
|
||||||
const { locale } = useGlobal()
|
const { locale } = useGlobal()
|
||||||
const meta = {
|
const meta = {
|
||||||
title: `${keyword || ''}${keyword ? ' | ' : ''}${locale.NAV.SEARCH} | ${
|
title: `${keyword || ''}${keyword ? ' | ' : ''}${locale.NAV.SEARCH} | ${siteInfo.title
|
||||||
siteInfo.title
|
}`,
|
||||||
}`,
|
|
||||||
description: siteInfo.title,
|
description: siteInfo.title,
|
||||||
slug: 'search/' + (keyword || ''),
|
slug: 'search/' + (keyword || ''),
|
||||||
type: 'website'
|
type: 'website'
|
||||||
@@ -111,7 +110,7 @@ async function filterByMemCache(allPosts, keyword) {
|
|||||||
indexContent = appendText(indexContent, properties, 'caption')
|
indexContent = appendText(indexContent, properties, 'caption')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// console.log('搜索是否命中缓存', page !== null, indexContent)
|
console.log('搜索是否命中缓存', page !== null, indexContent)
|
||||||
post.results = []
|
post.results = []
|
||||||
let hitCount = 0
|
let hitCount = 0
|
||||||
for (const i in indexContent) {
|
for (const i in indexContent) {
|
||||||
|
|||||||
@@ -8,13 +8,18 @@ import formatDate from '@/lib/formatDate'
|
|||||||
|
|
||||||
export const LayoutSlug = props => {
|
export const LayoutSlug = props => {
|
||||||
const { post, lock, validPassword } = props
|
const { post, lock, validPassword } = props
|
||||||
|
|
||||||
|
if (!post) {
|
||||||
|
return <LayoutBase {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
if (!lock && post?.blockMap?.block) {
|
if (!lock && post?.blockMap?.block) {
|
||||||
post.content = Object.keys(post.blockMap.block)
|
post.content = Object.keys(post.blockMap.block)
|
||||||
post.toc = getPageTableOfContents(post, post.blockMap)
|
post.toc = getPageTableOfContents(post, post.blockMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { locale } = useGlobal()
|
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 (
|
return (
|
||||||
<LayoutBase {...props}>
|
<LayoutBase {...props}>
|
||||||
@@ -34,7 +39,7 @@ export const LayoutSlug = props => {
|
|||||||
</Link>
|
</Link>
|
||||||
<span className='mr-2'>|</span>
|
<span className='mr-2'>|</span>
|
||||||
|
|
||||||
{post.type[0] !== 'Page' && (<>
|
{post?.type[0] !== 'Page' && (<>
|
||||||
<Link
|
<Link
|
||||||
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
|
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
|
||||||
passHref
|
passHref
|
||||||
@@ -60,7 +65,7 @@ export const LayoutSlug = props => {
|
|||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{post.blockMap && <NotionPage post={post} />}
|
{post && <NotionPage post={post} />}
|
||||||
</section>}
|
</section>}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,11 +10,15 @@ import ArticleAround from './ArticleAround'
|
|||||||
* @param {*} param0
|
* @param {*} param0
|
||||||
* @returns
|
* @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 { 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 ">
|
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">
|
<div className="w-full relative md:flex-shrink-0 overflow-hidden">
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
<img alt={post.title} src={post?.page_cover} className='object-center w-full' />
|
<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>
|
</Link>
|
||||||
<span className='mr-2'>|</span>
|
<span className='mr-2'>|</span>
|
||||||
|
|
||||||
{post.type[0] !== 'Page' && (<>
|
{post?.type[0] !== 'Page' && (<>
|
||||||
<Link
|
<Link
|
||||||
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
|
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
|
||||||
passHref
|
passHref
|
||||||
@@ -69,7 +73,7 @@ export default function ArticleDetail({ post, recommendPosts, prev, next }) {
|
|||||||
|
|
||||||
{/* Notion文章主体 */}
|
{/* Notion文章主体 */}
|
||||||
<section id='notion-article' className='px-1'>
|
<section id='notion-article' className='px-1'>
|
||||||
{post.blockMap && <NotionPage post={post} />}
|
{post && <NotionPage post={post} />}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section className="px-1 py-2 my-1 text-sm font-light overflow-auto text-gray-600 dark:text-gray-400">
|
<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 => {
|
export const LayoutSlug = props => {
|
||||||
const { post, lock, validPassword } = props
|
const { post, lock, validPassword } = props
|
||||||
|
|
||||||
|
if (!post) {
|
||||||
|
return <LayoutBase
|
||||||
|
headerSlot={<HeaderArticle {...props} />}
|
||||||
|
{...props}
|
||||||
|
showCategory={false}
|
||||||
|
showTag={false}
|
||||||
|
></LayoutBase>
|
||||||
|
}
|
||||||
|
|
||||||
if (!lock && post?.blockMap?.block) {
|
if (!lock && post?.blockMap?.block) {
|
||||||
post.content = Object.keys(post.blockMap.block)
|
post.content = Object.keys(post.blockMap.block)
|
||||||
post.toc = getPageTableOfContents(post, post.blockMap)
|
post.toc = getPageTableOfContents(post, post.blockMap)
|
||||||
@@ -50,7 +59,7 @@ export const LayoutSlug = props => {
|
|||||||
<article itemScope itemType="https://schema.org/Movie" className="subpixel-antialiased" >
|
<article itemScope itemType="https://schema.org/Movie" className="subpixel-antialiased" >
|
||||||
{/* Notion文章主体 */}
|
{/* Notion文章主体 */}
|
||||||
<section id='notion-article' className='px-5'>
|
<section id='notion-article' className='px-5'>
|
||||||
{post.blockMap && <NotionPage post={post} />}
|
{post && <NotionPage post={post} />}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section className="px-1 py-2 my-1 text-sm font-light overflow-auto text-gray-600 dark:text-gray-400">
|
<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'
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
export default function HeaderArticle({ post, siteInfo }) {
|
export default function HeaderArticle({ post, siteInfo }) {
|
||||||
|
if (!post) {
|
||||||
|
return <>loading...</>
|
||||||
|
}
|
||||||
const headerImage = post?.page_cover ? `url("${post.page_cover}")` : `url("${siteInfo?.pageCover}")`
|
const headerImage = post?.page_cover ? `url("${post.page_cover}")` : `url("${siteInfo?.pageCover}")`
|
||||||
const { isDarkMode } = useGlobal()
|
const { isDarkMode } = useGlobal()
|
||||||
|
|
||||||
const { locale } = useGlobal()
|
const { locale } = useGlobal()
|
||||||
const date = formatDate(
|
const date = formatDate(
|
||||||
post?.date?.start_date || post.createdTime,
|
post?.date?.start_date || post?.createdTime,
|
||||||
locale.LOCALE
|
locale.LOCALE
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -71,7 +74,7 @@ export default function HeaderArticle({ post, siteInfo }) {
|
|||||||
</>}
|
</>}
|
||||||
</div>
|
</div>
|
||||||
<div className='flex justify-center'>
|
<div className='flex justify-center'>
|
||||||
{post.type[0] !== 'Page' && (
|
{post?.type[0] !== 'Page' && (
|
||||||
<>
|
<>
|
||||||
<Link
|
<Link
|
||||||
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
|
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
|
||||||
|
|||||||
@@ -9,6 +9,12 @@ import { ArticleLock } from './components/ArticleLock'
|
|||||||
|
|
||||||
export const LayoutSlug = props => {
|
export const LayoutSlug = props => {
|
||||||
const { post, lock, validPassword } = props
|
const { post, lock, validPassword } = props
|
||||||
|
if (!post) {
|
||||||
|
return <LayoutBase
|
||||||
|
{...props}
|
||||||
|
showInfoCard={true}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
|
||||||
if (!lock && post?.blockMap?.block) {
|
if (!lock && post?.blockMap?.block) {
|
||||||
post.content = Object.keys(post.blockMap.block)
|
post.content = Object.keys(post.blockMap.block)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export const ArticleDetail = props => {
|
|||||||
const { locale } = useGlobal()
|
const { locale } = useGlobal()
|
||||||
|
|
||||||
const date = formatDate(
|
const date = formatDate(
|
||||||
post?.date?.start_date || post.createdTime,
|
post?.date?.start_date || post?.createdTime,
|
||||||
locale.LOCALE
|
locale.LOCALE
|
||||||
)
|
)
|
||||||
return <div id='container'>
|
return <div id='container'>
|
||||||
@@ -48,7 +48,7 @@ export const ArticleDetail = props => {
|
|||||||
</section>
|
</section>
|
||||||
{/* Notion文章主体 */}
|
{/* Notion文章主体 */}
|
||||||
<section id="notion-article" className="px-1 max-w-5xl">
|
<section id="notion-article" className="px-1 max-w-5xl">
|
||||||
{post.blockMap && (<NotionPage post={post} />)}
|
{post && (<NotionPage post={post} />)}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section className="px-1 py-2 my-1 text-sm font-light overflow-auto text-gray-600 dark:text-gray-400">
|
<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 [percent, changePercent] = useState(0)
|
||||||
const scrollListener = () => {
|
const scrollListener = () => {
|
||||||
const target = currentRef || document.getElementById('container')
|
const target = currentRef || document.getElementById('container')
|
||||||
console.log(target)
|
|
||||||
if (target) {
|
if (target) {
|
||||||
const clientHeight = target.clientHeight
|
const clientHeight = target.clientHeight
|
||||||
const scrollY = window.pageYOffset
|
const scrollY = window.pageYOffset
|
||||||
|
|||||||
@@ -11,6 +11,14 @@ import { ArticleLock } from './components/ArticleLock'
|
|||||||
|
|
||||||
export const LayoutSlug = (props) => {
|
export const LayoutSlug = (props) => {
|
||||||
const { post, latestPosts, lock, validPassword } = 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) {
|
if (!lock && post?.blockMap?.block) {
|
||||||
post.content = Object.keys(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 { post, recommendPosts, prev, next, showArticleInfo } = props
|
||||||
const url = BLOG.LINK + useRouter().asPath
|
const url = BLOG.LINK + useRouter().asPath
|
||||||
const { locale } = useGlobal()
|
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 ">
|
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"
|
<div itemScope itemType="https://schema.org/Movie"
|
||||||
@@ -29,7 +29,7 @@ export default function ArticleDetail(props) {
|
|||||||
>
|
>
|
||||||
|
|
||||||
{showArticleInfo && <header className='animate__slideInDown animate__animated'>
|
{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">
|
<div className="w-full relative md:flex-shrink-0 overflow-hidden">
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
<img alt={post.title} src={post?.page_cover} className='object-center w-full' />
|
<img alt={post.title} src={post?.page_cover} className='object-center w-full' />
|
||||||
@@ -51,7 +51,7 @@ export default function ArticleDetail(props) {
|
|||||||
</Link>
|
</Link>
|
||||||
<span className='mr-2'>|</span>
|
<span className='mr-2'>|</span>
|
||||||
</>}
|
</>}
|
||||||
{post.type[0] !== 'Page' && (<>
|
{post?.type[0] !== 'Page' && (<>
|
||||||
<Link
|
<Link
|
||||||
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
|
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
|
||||||
passHref
|
passHref
|
||||||
@@ -84,7 +84,7 @@ export default function ArticleDetail(props) {
|
|||||||
|
|
||||||
{/* Notion内容主体 */}
|
{/* Notion内容主体 */}
|
||||||
<article id='notion-article' className='px-1'>
|
<article id='notion-article' className='px-1'>
|
||||||
{post.blockMap && (<NotionPage post={post} />)}
|
{post && (<NotionPage post={post} />)}
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
<section className="px-1 py-2 my-1 text-sm font-light overflow-auto text-gray-600 dark:text-gray-400">
|
<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