Merge pull request #1865 from tangly1024/fix/some-bug-founded

Fix/some bug founded
This commit is contained in:
tangly1024
2024-02-02 11:48:21 +08:00
committed by GitHub
11 changed files with 49 additions and 28 deletions

View File

@@ -21,6 +21,11 @@ const Gitalk = ({ frontMatter }) => {
await loadExternalResource(gitalkCSSCDN, 'css')
await loadExternalResource(gitalkJSCDN, 'js')
const Gitalk = window.Gitalk
if (!Gitalk) {
// 可以加入延时重试
console.warn('Gitalk 初始化失败')
return
}
const gitalk = new Gitalk({
clientID: clientId,
clientSecret: clientSecret,

View File

@@ -85,7 +85,6 @@ const GlobalHead = (props) => {
* @param {*} router
*/
const getSEOMeta = (props, router, global) => {
console.log(props, router)
const { locale } = global
const { post, tag, category, page } = props
const keyword = router?.query?.s

View File

@@ -7,13 +7,6 @@ import { isBrowser } from '@/lib/utils'
import { siteConfig } from '@/lib/config'
import { NotionRenderer } from 'react-notion-x'
// 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

View File

@@ -34,7 +34,7 @@ export const memorize = (Component) => {
// 转换外链
export function sliceUrlFromHttp(str) {
// 检查字符串是否包含http
if (str.includes('http')) {
if (str.includes('http:') || str.includes('https:')) {
// 如果包含找到http的位置
const index = str.indexOf('http');
// 返回http之后的部分
@@ -48,7 +48,7 @@ export function sliceUrlFromHttp(str) {
// 检查是否外链
export function checkContainHttp(str) {
// 检查字符串是否包含http
if (str.includes('http')) {
if (str.includes('http:') || str.includes('https:')) {
// 如果包含找到http的位置
return str.indexOf('http') > -1
} else {

View File

@@ -5,6 +5,7 @@ import { idToUuid } from 'notion-utils'
import { getNotion } from '@/lib/notion/getNotion'
import Slug, { getRecommendPost } from '..'
import { uploadDataToAlgolia } from '@/lib/algolia'
import { checkContainHttp } from '@/lib/utils'
/**
* 根据notion的slug访问页面
@@ -30,8 +31,10 @@ export async function getStaticPaths() {
const from = 'slug-paths'
const { allPages } = await getGlobalData({ from })
return {
paths: allPages?.filter(row => hasMultipleSlashes(row.slug) && row.type.indexOf('Menu') < 0).map(row => ({ params: { prefix: row.slug.split('/')[0], slug: row.slug.split('/')[1], suffix: row.slug.split('/').slice(1) } })),
paths: allPages?.filter(row => hasMultipleSlashes(row.slug) && row.type.indexOf('Menu') < 0 && !checkContainHttp(row.slug))
.map(row => ({ params: { prefix: row.slug.split('/')[0], slug: row.slug.split('/')[1], suffix: row.slug.split('/').slice(1) } })),
fallback: true
}
}

View File

@@ -5,6 +5,7 @@ import { idToUuid } from 'notion-utils'
import { getNotion } from '@/lib/notion/getNotion'
import Slug, { getRecommendPost } from '..'
import { uploadDataToAlgolia } from '@/lib/algolia'
import { checkContainHttp } from '@/lib/utils'
/**
* 根据notion的slug访问页面
@@ -26,8 +27,10 @@ export async function getStaticPaths() {
const from = 'slug-paths'
const { allPages } = await getGlobalData({ from })
const paths = allPages?.filter(row => row.slug.indexOf('/') > 0 && !checkContainHttp(row.slug) && row.type.indexOf('Menu') < 0)
.map(row => ({ params: { prefix: row.slug.split('/')[0], slug: row.slug.split('/')[1] } }))
return {
paths: allPages?.filter(row => row.slug.indexOf('/') > 0 && row.type.indexOf('Menu') < 0).map(row => ({ params: { prefix: row.slug.split('/')[0], slug: row.slug.split('/')[1] } })),
paths: paths,
fallback: true
}
}

View File

@@ -8,7 +8,7 @@ import { getNotion } from '@/lib/notion/getNotion'
import { getPageTableOfContents } from '@/lib/notion/getPageTableOfContents'
import { getLayoutByTheme } from '@/themes/theme'
import md5 from 'js-md5'
import { isBrowser } from '@/lib/utils'
import { checkContainHttp, isBrowser } from '@/lib/utils'
import { uploadDataToAlgolia } from '@/lib/algolia'
import { siteConfig } from '@/lib/config'
@@ -82,8 +82,10 @@ export async function getStaticPaths() {
const from = 'slug-paths'
const { allPages } = await getGlobalData({ from })
const paths = allPages?.filter(row => row.slug.indexOf('/') > 0 && !checkContainHttp(row.slug) && row.type.indexOf('Menu') < 0)
.map(row => ({ params: { prefix: row.slug } }))
return {
paths: allPages?.filter(row => row.slug.indexOf('/') < 0 && row.type.indexOf('Menu') < 0).map(row => ({ params: { prefix: row.slug } })),
paths: paths,
fallback: true
}
}

View File

@@ -17,16 +17,21 @@ import useAdjustStyle from '@/hooks/useAdjustStyle'
// 各种扩展插件 这个要阻塞引入
import ExternalPlugins from '@/components/ExternalPlugins'
import { THEME } from '@/blog.config'
import GlobalHead from '@/components/GlobalHead'
import BLOG from '@/blog.config'
/**
* App挂载DOM 入口文件
* @param {*} param0
* @returns
*/
const MyApp = ({ Component, pageProps }) => {
// 一些可能出现 bug 的样式,可以统一放入该钩子进行调整
useAdjustStyle();
const route = useRouter()
const queryParam = useMemo(() => {
return getQueryParam(route.asPath, 'theme') || THEME
return getQueryParam(route.asPath, 'theme') || pageProps?.NOTION_CONFIG?.THEME || BLOG.THEME
}, [route])
// 整体布局

View File

@@ -65,13 +65,10 @@ const LayoutBase = props => {
{/* 通知横幅 */}
{router.route === '/'
? <>
<NoticeBar />
<Hero {...props} />
</>
<NoticeBar />
<Hero {...props} />
</>
: null}
<div className="max-w-[86rem] mx-auto px-3">
<WWAds className="w-full" orientation="horizontal" />
</div>
{fullWidth ? null : <PostHeader {...props} />}
</header>
)
@@ -270,11 +267,7 @@ const LayoutSlug = props => {
siteConfig('COMMENT_GITALK_CLIENT_ID') || siteConfig('COMMENT_WEBMENTION_ENABLE')
return (
<div
{...props}
showCategory={false}
showTag={false}
>
<>
<div className={`w-full ${fullWidth ? '' : 'xl:max-w-5xl'} ${hasCode ? 'xl:w-[73.15vw]' : ''} lg:hover:shadow lg:border rounded-2xl lg:px-2 lg:py-4 bg-white dark:bg-[#18171d] dark:border-gray-600 article`}>
{lock && <ArticleLock validPassword={validPassword} />}
@@ -334,7 +327,7 @@ const LayoutSlug = props => {
)}
</div>
<FloatTocButton {...props} />
</div>
</>
)
}

View File

@@ -41,6 +41,7 @@ const TopNav = props => {
useEffect(() => {
window.addEventListener('scroll', topNavStyleHandler)
router.events.on('routeChangeComplete', topNavStyleHandler)
topNavStyleHandler()
return () => {
router.events.off('routeChangeComplete', topNavStyleHandler)
window.removeEventListener('scroll', topNavStyleHandler)

View File

@@ -11,6 +11,7 @@ import TagGroups from './TagGroups'
import CONFIG from '../config'
import { siteConfig } from '@/lib/config'
import { useNextGlobal } from '..'
import { useRouter } from 'next/router'
let windowTop = 0
@@ -24,6 +25,7 @@ const TopNav = (props) => {
const { locale } = useGlobal()
const searchDrawer = useRef()
const collapseRef = useRef(null)
const router = useRouter()
const scrollTrigger = useCallback(throttle(() => {
const scrollS = window.scrollY
@@ -51,6 +53,21 @@ const TopNav = (props) => {
const [isOpen, changeShow] = useState(false)
// 监听滚动
useEffect(() => {
router.events.on('routeChangeComplete', menuCollapseHide)
return () => {
router.events.off('routeChangeComplete', menuCollapseHide)
}
}, [])
/**
* 点击切换页面后关闭这点菜单
*/
const menuCollapseHide = () => {
changeShow(false)
}
const toggleMenuOpen = () => {
changeShow(!isOpen)
}