From 0c415984556603e2958430f7c23807764c7ff74d Mon Sep 17 00:00:00 2001 From: anime Date: Fri, 20 Dec 2024 20:09:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=94=AF=E6=8C=81=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=86=85=E7=AB=99=E5=86=85=E9=93=BE=E6=8E=A5=E5=A4=9A=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E8=B7=B3=E8=BD=AC=E5=B9=B6=E4=BC=98=E5=8C=96=E6=80=A7?= =?UTF-8?q?=E8=83=BD):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit d35fcfdfaaef78d14cdaa7d88f69884f09c84277) --- lib/notion/convertInnerUrl.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 =