多语言微调

This commit is contained in:
tangly1024
2024-06-15 15:31:07 +08:00
parent 496306958f
commit 5f9263430b
2 changed files with 22 additions and 16 deletions

View File

@@ -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'
}
}
}