mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-05 07:26:46 +00:00
跳转页内链接处理
This commit is contained in:
@@ -80,6 +80,25 @@ const NotionPage = ({ post, className }) => {
|
|||||||
}
|
}
|
||||||
}, 800)
|
}, 800)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理页面内连接跳转
|
||||||
|
* 如果链接就是当前网站,则不打开新窗口访问
|
||||||
|
*/
|
||||||
|
if (isBrowser) {
|
||||||
|
const currentURL = window.location.origin + window.location.pathname
|
||||||
|
const allAnchorTags = document.getElementsByTagName('a') // 或者使用 document.querySelectorAll('a') 获取 NodeList
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
if (!post || !post.blockMap) {
|
if (!post || !post.blockMap) {
|
||||||
|
|||||||
Reference in New Issue
Block a user