From e65df5aac37e3867796c56ca8317ab49156d76b5 Mon Sep 17 00:00:00 2001 From: LooseLi <1329307562@qq.com> Date: Mon, 26 May 2025 16:36:07 +0800 Subject: [PATCH 1/8] =?UTF-8?q?fix:=20=E5=85=B3=E9=97=AD=E5=AF=B9=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=8F=98=E9=87=8F=E7=9A=84=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index f523d8f0..4adf6887 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -39,7 +39,7 @@ module.exports = { 'react/prop-types': 'off', 'space-before-function-paren': 0, 'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks - '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], // 确保未使用的变量报错 + '@typescript-eslint/no-unused-vars': 'off', // 关闭未使用的变量报错 '@typescript-eslint/explicit-function-return-type': 'off' // 关闭强制函数返回类型声明 }, overrides: [ From 13235b6cdb58e7498db429b0450d8dddbebcd306 Mon Sep 17 00:00:00 2001 From: LooseLi <1329307562@qq.com> Date: Mon, 26 May 2025 16:51:31 +0800 Subject: [PATCH 2/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20eslint=20?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/db/getSiteData.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/db/getSiteData.js b/lib/db/getSiteData.js index abf595ed..74cf1807 100755 --- a/lib/db/getSiteData.js +++ b/lib/db/getSiteData.js @@ -267,12 +267,13 @@ async function convertNotionToSiteDate(pageId, from, pageRecordMap) { categoryOptions: getCategoryOptions(schema) }) // 所有标签 + const tagSchemaOptions = getTagOptions(schema) const tagOptions = getAllTags({ - allPages, - tagOptions: getTagOptions(schema), + allPages: allPages ?? [], + tagOptions: tagSchemaOptions ?? [], NOTION_CONFIG - }) || null + }) ?? null // 旧的菜单 const customNav = getCustomNav({ allPages: collectionData.filter( From 1f691818f8cd646adc19eaf881e4f1b5a40b37e8 Mon Sep 17 00:00:00 2001 From: LooseLi <1329307562@qq.com> Date: Mon, 26 May 2025 16:55:44 +0800 Subject: [PATCH 3/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20eslint=20?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/db/getSiteData.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/db/getSiteData.js b/lib/db/getSiteData.js index 74cf1807..12e6df4c 100755 --- a/lib/db/getSiteData.js +++ b/lib/db/getSiteData.js @@ -281,7 +281,7 @@ async function convertNotionToSiteDate(pageId, from, pageRecordMap) { ) }) // 新的菜单 - const customMenu = await getCustomMenu({ collectionData, NOTION_CONFIG }) + const customMenu = getCustomMenu({ collectionData, NOTION_CONFIG }) const latestPosts = getLatestPosts({ allPages, from, latestPostCount: 6 }) const allNavPages = getNavPages({ allPages }) From 3366dd4a6c60ea45515d5dab29ad1c8a9ab730e1 Mon Sep 17 00:00:00 2001 From: LooseLi <1329307562@qq.com> Date: Mon, 26 May 2025 18:11:45 +0800 Subject: [PATCH 4/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20eslint=20?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/gitbook/components/ArticleAround.js | 4 +- themes/gitbook/index.js | 109 ++++++++++---------- themes/nobelium/components/ArticleFooter.js | 38 +++---- themes/plog/components/ArticleFooter.js | 38 +++---- themes/proxio/components/MenuList.js | 8 +- themes/starter/components/MenuList.js | 8 +- themes/theme.js | 6 +- 7 files changed, 108 insertions(+), 103 deletions(-) diff --git a/themes/gitbook/components/ArticleAround.js b/themes/gitbook/components/ArticleAround.js index 56db04ea..4125e1cc 100644 --- a/themes/gitbook/components/ArticleAround.js +++ b/themes/gitbook/components/ArticleAround.js @@ -7,10 +7,12 @@ import Link from 'next/link' * @returns */ export default function ArticleAround({ prev, next }) { + const { locale } = useGlobal() + if (!prev || !next) { return <> } - const { locale } = useGlobal() + return (
{ setHasRedirected(true) // 更新状态,防止多次执行 // 重定向到指定文章 - router.push(index).then(() => { - setTimeout(() => { - const article = document.querySelector( - '#article-wrapper #notion-article' - ) - if (!article) { - console.log( - '请检查您的Notion数据库中是否包含此slug页面: ', - index - ) + await router.push(index) - // 显示错误信息 - const containerInner = document.querySelector( - '#theme-gitbook #container-inner' - ) - const newHTML = `

配置有误

请在您的notion中添加一个slug为${index}的文章
` - containerInner?.insertAdjacentHTML('afterbegin', newHTML) - } - }, 2000) - }) + // 使用setTimeout检查页面加载情况 + setTimeout(() => { + const article = document.querySelector( + '#article-wrapper #notion-article' + ) + if (!article) { + console.log('请检查您的Notion数据库中是否包含此slug页面: ', index) + + // 显示错误信息 + const containerInner = document.querySelector( + '#theme-gitbook #container-inner' + ) + const newHTML = `

配置有误

请在您的notion中添加一个slug为${index}的文章
` + containerInner?.insertAdjacentHTML('afterbegin', newHTML) + } + }, 2000) } } @@ -320,21 +318,18 @@ const LayoutSlug = props => { useEffect(() => { // 404 if (!post) { - setTimeout( - () => { - if (isBrowser) { - const article = document.querySelector( - '#article-wrapper #notion-article' - ) - if (!article) { - router.push('/404').then(() => { - console.warn('找不到页面', router.asPath) - }) - } + setTimeout(() => { + if (isBrowser) { + const article = document.querySelector( + '#article-wrapper #notion-article' + ) + if (!article) { + router.push('/404').then(() => { + console.warn('找不到页面', router.asPath) + }) } - }, - waiting404 - ) + } + }, waiting404) } }, [post]) return ( @@ -451,16 +446,21 @@ const Layout404 = props => { }, 3000) }, []) - return <> -
-
-

404

-
-

{locale.NAV.PAGE_NOT_FOUND_REDIRECT}

-
-
+ return ( + <> +
+
+

+ + 404 +

+
+

{locale.NAV.PAGE_NOT_FOUND_REDIRECT}

+
+
+ ) } /** @@ -609,18 +609,17 @@ const LayoutDashboard = props => { } export { - Layout404, - LayoutArchive, - LayoutBase, - LayoutCategoryIndex, - LayoutDashboard, - LayoutIndex, - LayoutPostList, - LayoutSearch, - LayoutSignIn, - LayoutSignUp, - LayoutSlug, - LayoutTagIndex, - CONFIG as THEME_CONFIG + Layout404, + LayoutArchive, + LayoutBase, + LayoutCategoryIndex, + LayoutDashboard, + LayoutIndex, + LayoutPostList, + LayoutSearch, + LayoutSignIn, + LayoutSignUp, + LayoutSlug, + LayoutTagIndex, + CONFIG as THEME_CONFIG } - diff --git a/themes/nobelium/components/ArticleFooter.js b/themes/nobelium/components/ArticleFooter.js index 628dd05d..db4b5abf 100644 --- a/themes/nobelium/components/ArticleFooter.js +++ b/themes/nobelium/components/ArticleFooter.js @@ -12,22 +12,24 @@ export const ArticleFooter = props => { const router = useRouter() const { locale } = useGlobal() - return
- - - - - - -
+ return ( +
+ + + + + + +
+ ) } diff --git a/themes/plog/components/ArticleFooter.js b/themes/plog/components/ArticleFooter.js index ec65adba..56fc036b 100644 --- a/themes/plog/components/ArticleFooter.js +++ b/themes/plog/components/ArticleFooter.js @@ -13,22 +13,24 @@ export const ArticleFooter = props => { const router = useRouter() const { locale } = useGlobal() - return
- - - - - - -
+ return ( +
+ + + + + + +
+ ) } diff --git a/themes/proxio/components/MenuList.js b/themes/proxio/components/MenuList.js index 0352e8b2..ac5f7a0d 100644 --- a/themes/proxio/components/MenuList.js +++ b/themes/proxio/components/MenuList.js @@ -51,10 +51,6 @@ export const MenuList = props => { links = customMenu } - if (!links || links.length === 0) { - return null - } - const toggleMenu = () => { setShowMenu(!showMenu) // 切换菜单状态 } @@ -63,6 +59,10 @@ export const MenuList = props => { setShowMenu(false) }, [router]) + if (!links || links.length === 0) { + return null + } + return (
{/* 移动端菜单切换按钮 */} diff --git a/themes/starter/components/MenuList.js b/themes/starter/components/MenuList.js index 0352e8b2..ac5f7a0d 100644 --- a/themes/starter/components/MenuList.js +++ b/themes/starter/components/MenuList.js @@ -51,10 +51,6 @@ export const MenuList = props => { links = customMenu } - if (!links || links.length === 0) { - return null - } - const toggleMenu = () => { setShowMenu(!showMenu) // 切换菜单状态 } @@ -63,6 +59,10 @@ export const MenuList = props => { setShowMenu(false) }, [router]) + if (!links || links.length === 0) { + return null + } + return (
{/* 移动端菜单切换按钮 */} diff --git a/themes/theme.js b/themes/theme.js index 3d89f878..451c77bf 100644 --- a/themes/theme.js +++ b/themes/theme.js @@ -79,17 +79,17 @@ export const getBaseLayoutByTheme = theme => { */ export const DynamicLayout = props => { const { theme, layoutName } = props - const SelectedLayout = getLayoutByTheme({ layoutName, theme }) + const SelectedLayout = useLayoutByTheme({ layoutName, theme }) return } /** * 加载主题文件 - * @param {*} router + * @param {*} layoutName * @param {*} theme * @returns */ -export const getLayoutByTheme = ({ layoutName, theme }) => { +export const useLayoutByTheme = ({ layoutName, theme }) => { // const layoutName = getLayoutNameByPath(router.pathname, router.asPath) const LayoutComponents = ThemeComponents[layoutName] || ThemeComponents.LayoutSlug From 84236f3cffaa93b89e00f8acad1c655cc535893c Mon Sep 17 00:00:00 2001 From: LooseLi <1329307562@qq.com> Date: Tue, 27 May 2025 10:06:47 +0800 Subject: [PATCH 5/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20eslint=20?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugins/algolia.js | 2 +- lib/plugins/mailchimp.js | 16 ++++++++++------ lib/robots.txt.js | 2 +- lib/sitemap.xml.js | 2 +- middleware.ts | 2 +- next.config.js | 8 ++++---- pages/api/auth/callback/notion.ts | 5 ++++- pages/dashboard/[[...index]].js | 2 +- pages/search/[keyword]/index.js | 4 ++-- pages/search/[keyword]/page/[page].js | 4 ++-- pages/sign-in/[[...index]].js | 2 +- pages/sign-up/[[...index]].js | 2 +- 12 files changed, 29 insertions(+), 22 deletions(-) diff --git a/lib/plugins/algolia.js b/lib/plugins/algolia.js index d161bf58..e6c76422 100644 --- a/lib/plugins/algolia.js +++ b/lib/plugins/algolia.js @@ -6,7 +6,7 @@ import algoliasearch from 'algoliasearch' * 生成全文索引 * @param {*} allPages */ -const generateAlgoliaSearch = async ({ allPages, force = false }) => { +const generateAlgoliaSearch = ({ allPages, force = false }) => { allPages?.forEach(p => { // 判断这篇文章是否需要重新创建索引 if (p && !p.password) { diff --git a/lib/plugins/mailchimp.js b/lib/plugins/mailchimp.js index 1d8bd2e2..29171819 100644 --- a/lib/plugins/mailchimp.js +++ b/lib/plugins/mailchimp.js @@ -1,15 +1,19 @@ import BLOG from '@/blog.config' /** -* 订阅邮件-服务端接口 -* @param {*} email -* @returns -*/ -export default function subscribeToMailchimpApi({ email, first_name = '', last_name = '' }) { + * 订阅邮件-服务端接口 + * @param {*} email + * @returns + */ +export default function subscribeToMailchimpApi({ + email, + first_name = '', + last_name = '' +}) { const listId = BLOG.MAILCHIMP_LIST_ID // 替换为你的邮件列表 ID const apiKey = BLOG.MAILCHIMP_API_KEY // 替换为你的 API KEY if (!email || !listId || !apiKey) { - return {} + return Promise.resolve({}) } const data = { email_address: email, diff --git a/lib/robots.txt.js b/lib/robots.txt.js index 45e11606..63956845 100644 --- a/lib/robots.txt.js +++ b/lib/robots.txt.js @@ -1,6 +1,6 @@ import fs from 'fs' -export async function generateRobotsTxt(props) { +export function generateRobotsTxt(props) { const { siteInfo } = props const LINK = siteInfo?.link const content = ` diff --git a/lib/sitemap.xml.js b/lib/sitemap.xml.js index 1ff513f7..1c931a50 100644 --- a/lib/sitemap.xml.js +++ b/lib/sitemap.xml.js @@ -5,7 +5,7 @@ import { siteConfig } from './config' * 生成站点地图 * @param {*} param0 */ -export async function generateSitemapXml({ allPages, NOTION_CONFIG }) { +export function generateSitemapXml({ allPages, NOTION_CONFIG }) { let link = siteConfig('LINK', BLOG.LINK, NOTION_CONFIG) // 确保链接不以斜杠结尾 if (link && link.endsWith('/')) { diff --git a/middleware.ts b/middleware.ts index 550c6f8b..1906db68 100644 --- a/middleware.ts +++ b/middleware.ts @@ -64,7 +64,7 @@ const noAuthMiddleware = async (req: NextRequest, ev: any) => { * 鉴权中间件 */ const authMiddleware = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY - ? clerkMiddleware(async (auth, req) => { + ? clerkMiddleware((auth, req) => { const { userId } = auth() // 处理 /dashboard 路由的登录保护 if (isTenantRoute(req)) { diff --git a/next.config.js b/next.config.js index 3b8d7135..1bba8d1c 100644 --- a/next.config.js +++ b/next.config.js @@ -117,7 +117,7 @@ const nextConfig = { // 默认将feed重定向至 /public/rss/feed.xml redirects: process.env.EXPORT ? undefined - : async () => { + : () => { return [ { source: '/feed', @@ -129,7 +129,7 @@ const nextConfig = { // 重写url rewrites: process.env.EXPORT ? undefined - : async () => { + : () => { // 处理多语言重定向 const langsRewrites = [] if (BLOG.NOTION_PAGE_ID.indexOf(',') > 0) { @@ -176,7 +176,7 @@ const nextConfig = { }, headers: process.env.EXPORT ? undefined - : async () => { + : () => { return [ { source: '/:path*{/}?', @@ -217,7 +217,7 @@ const nextConfig = { experimental: { scrollRestoration: true }, - exportPathMap: async function ( + exportPathMap: function ( defaultPathMap, { dev, dir, outDir, distDir, buildId } ) { diff --git a/pages/api/auth/callback/notion.ts b/pages/api/auth/callback/notion.ts index b69a1982..467577f1 100644 --- a/pages/api/auth/callback/notion.ts +++ b/pages/api/auth/callback/notion.ts @@ -62,7 +62,10 @@ export default async function handler( } // 这里将用户数据写入到Notion数据库 - res.redirect(302, `/auth/result?${new URLSearchParams(redirectQuery)}`) + res.redirect( + 302, + `/auth/result?${new URLSearchParams(redirectQuery).toString()}` + ) } else { const redirectQuery = { msg: params?.statusText || '请求异常' } res.redirect( diff --git a/pages/dashboard/[[...index]].js b/pages/dashboard/[[...index]].js index 790bd723..330625e3 100644 --- a/pages/dashboard/[[...index]].js +++ b/pages/dashboard/[[...index]].js @@ -71,7 +71,7 @@ export async function getStaticProps({ locale }) { } } -export const getStaticPaths = async () => { +export const getStaticPaths = () => { return { paths: [ { params: { index: [] } }, // 对应首页路径 diff --git a/pages/search/[keyword]/index.js b/pages/search/[keyword]/index.js index b62ef8a9..4116e689 100644 --- a/pages/search/[keyword]/index.js +++ b/pages/search/[keyword]/index.js @@ -51,7 +51,7 @@ export async function getStaticProps({ params: { keyword }, locale }) { } } -export async function getStaticPaths() { +export function getStaticPaths() { return { paths: [{ params: { keyword: 'NotionNext' } }], fallback: true @@ -128,7 +128,7 @@ async function filterByMemCache(allPosts, keyword) { // console.log('全文搜索缓存', cacheKey, page != null) post.results = [] let hitCount = 0 - for (const i in indexContent) { + for (const i of indexContent) { const c = indexContent[i] if (!c) { continue diff --git a/pages/search/[keyword]/page/[page].js b/pages/search/[keyword]/page/[page].js index e0d20acc..371d23e7 100644 --- a/pages/search/[keyword]/page/[page].js +++ b/pages/search/[keyword]/page/[page].js @@ -50,7 +50,7 @@ export async function getStaticProps({ params: { keyword, page }, locale }) { } } -export async function getStaticPaths() { +export function getStaticPaths() { return { paths: [{ params: { keyword: 'NotionNext', page: '1' } }], fallback: true @@ -135,7 +135,7 @@ async function filterByMemCache(allPosts, keyword) { // console.log('全文搜索缓存', cacheKey, page != null) post.results = [] let hitCount = 0 - for (const i in indexContent) { + for (const i of indexContent) { const c = indexContent[i] if (!c) { continue diff --git a/pages/sign-in/[[...index]].js b/pages/sign-in/[[...index]].js index 135ae292..f11964f1 100644 --- a/pages/sign-in/[[...index]].js +++ b/pages/sign-in/[[...index]].js @@ -37,7 +37,7 @@ export async function getStaticProps(req) { * catch-all route for clerk * @returns */ -export async function getStaticPaths() { +export function getStaticPaths() { return { paths: [ { params: { index: [] } }, // 使 /sign-in 路径可访问 diff --git a/pages/sign-up/[[...index]].js b/pages/sign-up/[[...index]].js index f721ec6f..d5120600 100644 --- a/pages/sign-up/[[...index]].js +++ b/pages/sign-up/[[...index]].js @@ -36,7 +36,7 @@ export async function getStaticProps(req) { * catch-all route for clerk * @returns */ -export async function getStaticPaths() { +export function getStaticPaths() { return { paths: [ { params: { index: [] } }, // 使 /sign-up 路径可访问 From d9bbf58aa6614db9940326807c445d895747b95f Mon Sep 17 00:00:00 2001 From: LooseLi <1329307562@qq.com> Date: Tue, 27 May 2025 10:11:59 +0800 Subject: [PATCH 6/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20TypeScript=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/CustomNotionApi.ts | 60 ++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/lib/notion/CustomNotionApi.ts b/lib/notion/CustomNotionApi.ts index fc5f46c9..2266055e 100644 --- a/lib/notion/CustomNotionApi.ts +++ b/lib/notion/CustomNotionApi.ts @@ -1,16 +1,29 @@ -const axios = require('axios') +import axios from 'axios' + +// 定义内容项的接口 +interface ContentItem { + type: string + content: string +} + +// 定义Notion块的接口 +interface NotionBlock { + object: string + type: string + [key: string]: unknown +} // 发送 Notion API 请求 async function postNotion( - properties: any, + properties: Record, databaseId: string, - listContentMain: any[], + listContentMain: ContentItem[], token: string -) { +): Promise<{ status: number; data: Record }> { const url = 'https://api.notion.com/v1/pages' const children = listContentMain - .map(contentMain => { + .map((contentMain: ContentItem): NotionBlock | null => { if (contentMain.type === 'paragraph') { return { object: 'block', @@ -51,14 +64,21 @@ async function postNotion( try { const response = await axios.post(url, payload, { headers }) return response - } catch (error: any) { + } catch (error) { console.error('写入Notion异常', error) - throw new Error(`Error posting to Notion: ${error.message}`) + const errorMessage = error instanceof Error ? error.message : String(error) + throw new Error(`Error posting to Notion: ${errorMessage}`) } } +// 定义响应结果的接口 +interface NotionResponse { + status: number + data: Record +} + // 处理响应结果 -function responseResult(response: { status: number; data: any }) { +function responseResult(response: NotionResponse): void { if (response.status === 200) { console.log('成功...') console.log(response.data) @@ -68,15 +88,25 @@ function responseResult(response: { status: number; data: any }) { } } +// 定义用户属性的接口 +interface UserProperties { + id: string + avatar: string + name: string + mail: string + lastLoginTime: string + token: string +} + // 准备属性字段 function notionProperty( - id: any, - avatar: any, - name: any, - mail: any, - lastLoginTime: any, - token: any -) { + id: string, + avatar: string, + name: string, + mail: string, + lastLoginTime: string, + token: string +): Record { return { id: { rich_text: [ From e631507ce268b18616edb93740bf17666f999147 Mon Sep 17 00:00:00 2001 From: LooseLi <1329307562@qq.com> Date: Tue, 27 May 2025 10:52:32 +0800 Subject: [PATCH 7/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20eslint=20?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/AOSAnimation.js | 2 +- components/AdBlockDetect.js | 9 ++++++--- components/ExternalPlugins.js | 7 +++---- components/Fireworks.js | 2 +- components/GoogleAdsense.js | 2 +- components/Lenis.js | 12 ++++++++---- components/NotionPage.js | 2 +- components/PrismMac.js | 4 ++-- components/Select.js | 14 ++++++-------- lib/cache/local_file_cache.js | 24 +++++++++++++----------- lib/cache/redis_cache.js | 6 +++--- lib/global.js | 11 +++++++---- 12 files changed, 52 insertions(+), 43 deletions(-) diff --git a/components/AOSAnimation.js b/components/AOSAnimation.js index 7d246def..3ba87e0d 100644 --- a/components/AOSAnimation.js +++ b/components/AOSAnimation.js @@ -8,7 +8,7 @@ import { useEffect } from 'react' * https://michalsnik.github.io/aos/ */ export default function AOSAnimation() { - const initAOS = async () => { + const initAOS = () => { Promise.all([ loadExternalResource('/js/aos.js', 'js'), loadExternalResource('/css/aos.css', 'css') diff --git a/components/AdBlockDetect.js b/components/AdBlockDetect.js index 00758a08..b2b965eb 100644 --- a/components/AdBlockDetect.js +++ b/components/AdBlockDetect.js @@ -14,16 +14,19 @@ export default function AdBlockDetect() { const wwadsCns = document.getElementsByClassName('wwads-cn') if (wwadsCns && wwadsCns.length > 0) { for (const wwadsCn of wwadsCns) { - wwadsCn.insertAdjacentHTML('beforeend', "") + wwadsCn.insertAdjacentHTML( + 'beforeend', + "" + ) } } - }; + } // check document ready function docReady(t) { document.readyState === 'complete' || document.readyState === 'interactive' - ? setTimeout(t, 1) + ? setTimeout(() => t(), 1) : document.addEventListener('DOMContentLoaded', t) } diff --git a/components/ExternalPlugins.js b/components/ExternalPlugins.js index fd92820e..d31ec5be 100644 --- a/components/ExternalPlugins.js +++ b/components/ExternalPlugins.js @@ -13,7 +13,6 @@ import WebWhiz from './Webwhiz' import { useGlobal } from '@/lib/global' import IconFont from './IconFont' - /** * 各种插件脚本 * @param {*} props @@ -22,7 +21,7 @@ import IconFont from './IconFont' const ExternalPlugin = props => { // 读取自Notion的配置 const { NOTION_CONFIG } = props - const {lang} = useGlobal() + const { lang } = useGlobal() const DISABLE_PLUGIN = siteConfig('DISABLE_PLUGIN', null, NOTION_CONFIG) const THEME_SWITCH = siteConfig('THEME_SWITCH', null, NOTION_CONFIG) const DEBUG = siteConfig('DEBUG', null, NOTION_CONFIG) @@ -172,7 +171,7 @@ const ExternalPlugin = props => { setTimeout(() => { // 映射url - convertInnerUrl({ allPages:props?.allNavPages, lang:lang }) + convertInnerUrl({ allPages: props?.allNavPages, lang: lang }) }, 500) }, [router]) @@ -474,7 +473,7 @@ const DifyChatbot = dynamic(() => import('@/components/DifyChatbot'), { }) const Analytics = dynamic( () => - import('@vercel/analytics/react').then(async m => { + import('@vercel/analytics/react').then(m => { return m.Analytics }), { ssr: false } diff --git a/components/Fireworks.js b/components/Fireworks.js index a57a3023..9cefea05 100644 --- a/components/Fireworks.js +++ b/components/Fireworks.js @@ -16,7 +16,7 @@ const Fireworks = () => { useEffect(() => { // 异步加载 - async function loadFireworks() { + function loadFireworks() { loadExternalResource( 'https://cdnjs.snrat.com/ajax/libs/animejs/3.2.1/anime.min.js', 'js' diff --git a/components/GoogleAdsense.js b/components/GoogleAdsense.js index 12aacc95..5e9abe7b 100644 --- a/components/GoogleAdsense.js +++ b/components/GoogleAdsense.js @@ -60,7 +60,7 @@ function getNodesWithAdsByGoogleClass(node) { * 初始化谷歌广告 * @returns */ -export const initGoogleAdsense = async ADSENSE_GOOGLE_ID => { +export const initGoogleAdsense = ADSENSE_GOOGLE_ID => { console.log('Load Adsense') loadExternalResource( `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${ADSENSE_GOOGLE_ID}`, diff --git a/components/Lenis.js b/components/Lenis.js index 43b1c062..677ba758 100644 --- a/components/Lenis.js +++ b/components/Lenis.js @@ -12,7 +12,9 @@ const Lenis = () => { useEffect(() => { // 异步加载 async function loadLenis() { - loadExternalResource('/js/lenis.js', 'js').then(() => { + try { + await loadExternalResource('/js/lenis.js', 'js') + // console.log('Lenis', window.Lenis) if (!window.Lenis) { console.error('Lenis not loaded') @@ -23,14 +25,14 @@ const Lenis = () => { // 创建 Lenis 实例 const lenis = new Lenis({ duration: 1.2, - easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou + easing: t => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou direction: 'vertical', // vertical, horizontal gestureDirection: 'vertical', // vertical, horizontal, both smooth: true, mouseMultiplier: 1, smoothTouch: false, touchMultiplier: 2, - infinite: false, + infinite: false }) // 存储实例到 ref @@ -48,7 +50,9 @@ const Lenis = () => { } requestAnimationFrame(raf) - }) + } catch (error) { + console.error('Failed to load Lenis:', error) + } } loadLenis() diff --git a/components/NotionPage.js b/components/NotionPage.js index 1e5bd607..586e0c0c 100644 --- a/components/NotionPage.js +++ b/components/NotionPage.js @@ -228,7 +228,7 @@ function getMediumZoomMargin() { // 代码 const Code = dynamic( () => - import('react-notion-x/build/third-party/code').then(async m => { + import('react-notion-x/build/third-party/code').then(m => { return m.Code }), { ssr: false } diff --git a/components/PrismMac.js b/components/PrismMac.js index 7e81fc01..a0aff890 100644 --- a/components/PrismMac.js +++ b/components/PrismMac.js @@ -160,8 +160,8 @@ const renderCollapseCode = (codeCollapse, codeCollapseExpandDefault) => { /** * 将mermaid语言 渲染成图片 */ -const renderMermaid = async(mermaidCDN) => { - const observer = new MutationObserver(async mutationsList => { +const renderMermaid = mermaidCDN => { + const observer = new MutationObserver(mutationsList => { for (const m of mutationsList) { if (m.target.className === 'notion-code language-mermaid') { const chart = m.target.querySelector('code').textContent diff --git a/components/Select.js b/components/Select.js index 3ab8cb73..d038dae8 100644 --- a/components/Select.js +++ b/components/Select.js @@ -4,21 +4,19 @@ import React from 'react' * 下拉单选框 */ class Select extends React.Component { - constructor (props) { - super(props) - this.handleChange = this.handleChange.bind(this) - } - - handleChange (event) { + handleChange = event => { const { onChange } = this.props onChange(event.target.value) } - render () { + render() { return (
- {this.props.options?.map(o => (