diff --git a/lib/notion/convertInnerUrl.js b/lib/notion/convertInnerUrl.js index 981722f7..8762d805 100644 --- a/lib/notion/convertInnerUrl.js +++ b/lib/notion/convertInnerUrl.js @@ -8,8 +8,15 @@ import { checkStrIsNotionId, getLastPartOfUrl, isBrowser } from '../utils' */ export const convertInnerUrl = allPages => { if (isBrowser) { + const allAnchorTags = document + ?.getElementById('notion-article') + ?.getElementsByTagName('a') + + if (!allAnchorTags) { + return + } const currentURL = window.location.origin + window.location.pathname - const allAnchorTags = document.getElementsByTagName('a') // 或者使用 document.querySelectorAll('a') 获取 NodeList + // url替换成slug for (const anchorTag of allAnchorTags) { // 检查url if (anchorTag?.href) { @@ -24,20 +31,19 @@ export const convertInnerUrl = allPages => { } } } + } - for (const anchorTag of allAnchorTags) { - if (anchorTag?.target === '_blank') { - const hrefWithoutQueryHash = anchorTag.href - .split('?')[0] - .split('#')[0] - const hrefWithRelativeHash = - currentURL.split('#')[0] || '' + anchorTag.href.split('#')[1] || '' - if ( - currentURL === hrefWithoutQueryHash || - currentURL === hrefWithRelativeHash - ) { - anchorTag.target = '_self' - } + // 链接在当前页面打开 + for (const anchorTag of allAnchorTags) { + if (anchorTag?.target === '_blank') { + const hrefWithoutQueryHash = anchorTag.href.split('?')[0].split('#')[0] + const hrefWithRelativeHash = + currentURL.split('#')[0] || '' + anchorTag.href.split('#')[1] || '' + if ( + currentURL === hrefWithoutQueryHash || + currentURL === hrefWithRelativeHash + ) { + anchorTag.target = '_self' } } } diff --git a/themes/heo/components/MenuItemDrop.js b/themes/heo/components/MenuItemDrop.js index fd7e35c7..2e8709ff 100644 --- a/themes/heo/components/MenuItemDrop.js +++ b/themes/heo/components/MenuItemDrop.js @@ -13,6 +13,8 @@ export const MenuItemDrop = ({ link }) => {