diff --git a/lib/notion/convertInnerUrl.js b/lib/notion/convertInnerUrl.js index 0a8cfbce..76317a1a 100644 --- a/lib/notion/convertInnerUrl.js +++ b/lib/notion/convertInnerUrl.js @@ -1,5 +1,6 @@ import { idToUuid } from 'notion-utils' import { checkStrIsNotionId, getLastPartOfUrl, isBrowser } from '../utils' +import { loadLangFromLocalStorage } from '@/lib/lang' /** * 处理页面内连接跳转: @@ -17,11 +18,13 @@ export const convertInnerUrl = allPages => { if (!allAnchorTags) { return } - - const currentURL = window.location.origin + window.location.pathname - // url替换成slug + const { origin, pathname } = window.location; + const currentURL = origin + pathname + const currentPathLang = pathname.split('/').filter(Boolean)[0] + const lang = loadLangFromLocalStorage().split(/[-_]/)[0] + const langPrefix = lang === currentPathLang ? '/' + lang : '' for (const anchorTag of allAnchorTags) { - // 检查url + // url替换成slug if (anchorTag?.href) { // 如果url是一个Notion_id,尝试匹配成博客的文章内链 const slug = getLastPartOfUrl(anchorTag.href) @@ -31,14 +34,11 @@ export const convertInnerUrl = allPages => { return find }) if (slugPage) { - anchorTag.href = slugPage?.href + anchorTag.href = langPrefix + slugPage?.href } } } - } - - // 链接在当前页面打开 - for (const anchorTag of allAnchorTags) { + // 链接在当前页面打开 if (anchorTag?.target === '_blank') { const hrefWithoutQueryHash = anchorTag.href.split('?')[0].split('#')[0] const hrefWithRelativeHash =