mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
SEO 优化首屏加载体积
This commit is contained in:
12
components/AOSAnimation.js
Normal file
12
components/AOSAnimation.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import AOS from 'aos'
|
||||
import { isBrowser } from 'react-notion-x'
|
||||
|
||||
/**
|
||||
* 加载滚动动画
|
||||
* https://michalsnik.github.io/aos/
|
||||
*/
|
||||
export default function AOSAnimation() {
|
||||
if (isBrowser) {
|
||||
AOS.init()
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,12 @@ const katexSettings = {
|
||||
strict: false
|
||||
}
|
||||
|
||||
/**
|
||||
* 数学公式
|
||||
* @param {} param0
|
||||
* @returns
|
||||
*/
|
||||
export const Equation = ({ block, math, inline = false, className, ...rest }) => {
|
||||
// const { recordMap } = useNotionContext()
|
||||
math = math || getBlockTitle(block, null)
|
||||
if (!math) return null
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ const VConsole = dynamic(() => import('@/components/VConsole'), { ssr: false })
|
||||
const CustomContextMenu = dynamic(() => import('@/components/CustomContextMenu'), { ssr: false })
|
||||
const DisableCopy = dynamic(() => import('@/components/DisableCopy'), { ssr: false })
|
||||
const AdBlockDetect = dynamic(() => import('@/components/AdBlockDetect'), { ssr: false })
|
||||
const LoadingProgress = dynamic(() => import('@/components/LoadingProgress'), { ssr: false })
|
||||
const AosAnimation = dynamic(() => import('@/components/AosAnimation'), { ssr: false })
|
||||
|
||||
/**
|
||||
* 各种插件脚本
|
||||
@@ -91,6 +93,8 @@ const ExternalPlugin = (props) => {
|
||||
{WEB_WHIZ_ENABLED && <WebWhiz />}
|
||||
{AD_WWADS_BLOCK_DETECT && <AdBlockDetect />}
|
||||
<VConsole />
|
||||
<LoadingProgress />
|
||||
<AosAnimation />
|
||||
|
||||
{CHATBASE_ID && (<>
|
||||
<script id={CHATBASE_ID} src="https://www.chatbase.co/embed.min.js" defer />
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import KaTeX from 'katex'
|
||||
import React from 'react'
|
||||
import { memo, useEffect, useState } from 'react'
|
||||
|
||||
/**
|
||||
* 数学公式
|
||||
* @param {*} param0
|
||||
* @returns
|
||||
*/
|
||||
const TeX = ({
|
||||
children,
|
||||
math,
|
||||
@@ -13,9 +18,9 @@ const TeX = ({
|
||||
}) => {
|
||||
const Component = asComponent || (block ? 'div' : 'span')
|
||||
const content = (children ?? math)
|
||||
const [state, setState] = React.useState({ innerHtml: '' })
|
||||
const [state, setState] = useState({ innerHtml: '' })
|
||||
|
||||
React.useEffect(() => {
|
||||
useEffect(() => {
|
||||
try {
|
||||
const innerHtml = KaTeX.renderToString(content, {
|
||||
displayMode: true,
|
||||
@@ -50,4 +55,4 @@ const TeX = ({
|
||||
)
|
||||
}
|
||||
|
||||
export default React.memo(TeX)
|
||||
export default memo(TeX)
|
||||
|
||||
@@ -4,6 +4,10 @@ import { useGlobal } from '@/lib/global'
|
||||
import { loadExternalResource } from '@/lib/utils'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
/**
|
||||
* 网页动画
|
||||
* @returns
|
||||
*/
|
||||
export default function Live2D() {
|
||||
const { theme, switchTheme } = useGlobal()
|
||||
const showPet = JSON.parse(siteConfig('WIDGET_PET'))
|
||||
|
||||
29
components/LoadingProgress.js
Normal file
29
components/LoadingProgress.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useRouter } from 'next/router'
|
||||
import NProgress from 'nprogress'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
/**
|
||||
* 出现页面加载进度条
|
||||
*/
|
||||
export default function LoadingProgress() {
|
||||
const router = useRouter()
|
||||
// 加载进度条
|
||||
useEffect(() => {
|
||||
const handleStart = (url) => {
|
||||
NProgress.start()
|
||||
}
|
||||
|
||||
const handleStop = () => {
|
||||
NProgress.done()
|
||||
}
|
||||
|
||||
router.events.on('routeChangeStart', handleStart)
|
||||
router.events.on('routeChangeError', handleStop)
|
||||
router.events.on('routeChangeComplete', handleStop)
|
||||
return () => {
|
||||
router.events.off('routeChangeStart', handleStart)
|
||||
router.events.off('routeChangeComplete', handleStop)
|
||||
router.events.off('routeChangeError', handleStop)
|
||||
}
|
||||
}, [router])
|
||||
}
|
||||
@@ -1,20 +1,25 @@
|
||||
import { NotionRenderer } from 'react-notion-x'
|
||||
import dynamic from 'next/dynamic'
|
||||
import mediumZoom from '@fisch0920/medium-zoom'
|
||||
import React, { useEffect, useRef } from 'react'
|
||||
// import { Code } from 'react-notion-x/build/third-party/code'
|
||||
import TweetEmbed from 'react-tweet-embed'
|
||||
import { useEffect, useRef } from 'react'
|
||||
import 'katex/dist/katex.min.css'
|
||||
import { mapImgUrl } from '@/lib/notion/mapImage'
|
||||
import { isBrowser } from '@/lib/utils'
|
||||
import { siteConfig } from '@/lib/config'
|
||||
|
||||
// Notion渲染
|
||||
const NotionRenderer = dynamic(() => import('react-notion-x').then(async (m) => {
|
||||
return m.NotionRenderer
|
||||
}), {
|
||||
ssr: false
|
||||
})
|
||||
|
||||
const Code = dynamic(() =>
|
||||
import('react-notion-x/build/third-party/code').then(async (m) => {
|
||||
return m.Code
|
||||
}), { ssr: false }
|
||||
)
|
||||
|
||||
// 公式
|
||||
const Equation = dynamic(() =>
|
||||
import('@/components/Equation').then(async (m) => {
|
||||
// 化学方程式
|
||||
@@ -36,6 +41,13 @@ const PrismMac = dynamic(() => import('@/components/PrismMac'), {
|
||||
ssr: false
|
||||
})
|
||||
|
||||
/**
|
||||
* tweet嵌入
|
||||
*/
|
||||
const TweetEmbed = dynamic(() => import('react-tweet-embed'), {
|
||||
ssr: false
|
||||
})
|
||||
|
||||
const Collection = dynamic(() =>
|
||||
import('react-notion-x/build/third-party/collection').then((m) => m.Collection), { ssr: true }
|
||||
)
|
||||
|
||||
@@ -1,29 +1,21 @@
|
||||
import { siteConfig } from '@/lib/config'
|
||||
import { useRouter } from 'next/router'
|
||||
import React from 'react'
|
||||
import ShareButtons from './ShareButtons'
|
||||
import dynamic from 'next/dynamic'
|
||||
|
||||
const ShareButtons = dynamic(() => import('@/components/ShareButtons'), { ssr: false })
|
||||
|
||||
/**
|
||||
* 分享栏
|
||||
* @param {} param0
|
||||
* @returns
|
||||
*/
|
||||
const ShareBar = ({ post }) => {
|
||||
const router = useRouter()
|
||||
const title = siteConfig('TITLE')
|
||||
|
||||
if (!JSON.parse(siteConfig('POST_SHARE_BAR_ENABLE')) || !post || post?.type !== 'Post') {
|
||||
return <></>
|
||||
}
|
||||
|
||||
const shareUrl = siteConfig('LINK') + router.asPath
|
||||
|
||||
return <div className='m-1 overflow-x-auto'>
|
||||
<div className='flex w-full md:justify-end'>
|
||||
<ShareButtons shareUrl={shareUrl} title={post.title} image={post.pageCover} body={
|
||||
post?.title +
|
||||
' | ' +
|
||||
title +
|
||||
' ' +
|
||||
shareUrl +
|
||||
' ' +
|
||||
post?.summary
|
||||
} />
|
||||
<ShareButtons post={post} />
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { siteConfig } from '@/lib/config'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import copy from 'copy-to-clipboard'
|
||||
import dynamic from 'next/dynamic'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useState } from 'react'
|
||||
|
||||
import {
|
||||
@@ -56,7 +57,13 @@ const QrCode = dynamic(() => import('@/components/QrCode'), { ssr: false })
|
||||
* @param {*} param0
|
||||
* @returns
|
||||
*/
|
||||
const ShareButtons = ({ shareUrl, title, body, image }) => {
|
||||
const ShareButtons = ({ post }) => {
|
||||
const router = useRouter()
|
||||
const shareUrl = siteConfig('LINK') + router.asPath
|
||||
const title = post.title || siteConfig('TITLE')
|
||||
const image = post.pageCover
|
||||
const body = post?.title + ' | ' + title + ' ' + shareUrl + ' ' + post?.summary
|
||||
|
||||
const services = siteConfig('POSTS_SHARE_SERVICES').split(',')
|
||||
const titleWithSiteInfo = title + ' | ' + siteConfig('TITLE')
|
||||
const { locale } = useGlobal()
|
||||
|
||||
Reference in New Issue
Block a user