mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-24 15:09:51 +00:00
多语言微调
This commit is contained in:
@@ -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'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user