mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-30 15:10:11 +00:00
Notion内链自动替换
This commit is contained in:
@@ -47,9 +47,6 @@ const NotionPage = ({ post, className }) => {
|
||||
processDisableDatabaseUrl()
|
||||
}
|
||||
|
||||
// 处理页内的url
|
||||
processPageUrl()
|
||||
|
||||
/**
|
||||
* 放大查看图片时替换成高清图像
|
||||
*/
|
||||
@@ -146,36 +143,6 @@ const processGalleryImg = zoom => {
|
||||
}, 800)
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理页面内连接跳转:
|
||||
* 1. 若是本站域名,则在当前窗口打开、不开新窗口
|
||||
* 2. 若是Notion笔记中的内链,尝试转换成博客中现有的文章地址
|
||||
*/
|
||||
const processPageUrl = () => {
|
||||
if (isBrowser) {
|
||||
const currentURL = window.location.origin + window.location.pathname
|
||||
const allAnchorTags = document.getElementsByTagName('a') // 或者使用 document.querySelectorAll('a') 获取 NodeList
|
||||
for (const anchorTag of allAnchorTags) {
|
||||
// 检查url
|
||||
if (anchorTag.href) {
|
||||
// 如果是notion页面间的内链,尝试匹配成博客的文章链接
|
||||
}
|
||||
|
||||
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'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 根据url参数自动滚动到指定区域
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user