diff --git a/components/ExternalPlugins.js b/components/ExternalPlugins.js index c2bf54d5..65932a39 100644 --- a/components/ExternalPlugins.js +++ b/components/ExternalPlugins.js @@ -10,6 +10,7 @@ import { initGoogleAdsense } from './GoogleAdsense' import Head from 'next/head' import ExternalScript from './ExternalScript' import WebWhiz from './Webwhiz' +import { useGlobal } from '@/lib/global' /** * 各种插件脚本 @@ -19,6 +20,7 @@ import WebWhiz from './Webwhiz' const ExternalPlugin = props => { // 读取自Notion的配置 const { NOTION_CONFIG } = props + 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) @@ -166,7 +168,7 @@ const ExternalPlugin = props => { setTimeout(() => { // 映射url - convertInnerUrl(props?.allNavPages) + convertInnerUrl({ allPages:props?.allNavPages, lang:lang }) }, 500) }, [router]) diff --git a/lib/lang.js b/lib/lang.js index 17a4189e..47bb7093 100644 --- a/lib/lang.js +++ b/lib/lang.js @@ -121,14 +121,4 @@ export const redirectUserLang = (lang, pageId) => { } } } -} - -/** - * 获取当前 Next.js 路由下的 locale - * @returns 当前路由下的 locale - */ -export function getCurrentLang() { - const router = useRouter() - let currentLang = router.locale - return currentLang -} +} \ No newline at end of file diff --git a/lib/notion/convertInnerUrl.js b/lib/notion/convertInnerUrl.js index 913fba9e..16ef17c0 100644 --- a/lib/notion/convertInnerUrl.js +++ b/lib/notion/convertInnerUrl.js @@ -1,13 +1,14 @@ import { idToUuid } from 'notion-utils' import { checkStrIsNotionId, getLastPartOfUrl, isBrowser } from '../utils' import { getCurrentLang } from '@/lib/lang' +import BLOG from '@/blog.config' /** * 处理页面内连接跳转: * 1.若是本站域名,则在当前窗口打开、不开新窗口 * 2.url是notion-id,转成站内文章链接 */ -export const convertInnerUrl = allPages => { +export const convertInnerUrl = ({allPages,lang}) => { if (!isBrowser) { return } @@ -21,7 +22,6 @@ export const convertInnerUrl = allPages => { const { origin, pathname } = window.location const currentURL = origin + pathname const currentPathLang = pathname.split('/').filter(Boolean)[0] - const lang = getCurrentLang const langPrefix = lang === currentPathLang ? '/' + lang : '' for (const anchorTag of allAnchorTags) { // url替换成slug