gallery视图自动替换url

This commit is contained in:
tangly1024.com
2025-03-04 13:54:46 +08:00
parent faf58eff06
commit 8688278e02
2 changed files with 19 additions and 5 deletions

View File

@@ -165,7 +165,7 @@ const ExternalPlugin = props => {
}
setTimeout(() => {
// 映射url
// 将notion-id格式的url转成自定义slug
convertInnerUrl(props?.allNavPages)
}, 500)
}, [router])

View File

@@ -1,6 +1,6 @@
import { loadLangFromLocalStorage } from '@/lib/lang'
import { idToUuid } from 'notion-utils'
import { checkStrIsNotionId, getLastPartOfUrl, isBrowser } from '../utils'
import { loadLangFromLocalStorage } from '@/lib/lang'
/**
* 处理页面内连接跳转:
@@ -13,12 +13,13 @@ export const convertInnerUrl = allPages => {
}
const allAnchorTags = document
?.getElementById('notion-article')
?.querySelectorAll('a.notion-link')
?.querySelectorAll('a.notion-link, a.notion-collection-card')
if (!allAnchorTags) {
return
}
const { origin, pathname } = window.location;
const { origin, pathname } = window.location
const currentURL = origin + pathname
const currentPathLang = pathname.split('/').filter(Boolean)[0]
const lang = loadLangFromLocalStorage().split(/[-_]/)[0]
@@ -49,5 +50,18 @@ export const convertInnerUrl = allPages => {
anchorTag.target = '_self'
}
}
// 如果链接以#号结尾,则强制在新窗口打开
if (anchorTag.href.endsWith('#')) {
anchorTag.target = '_blank'
}
}
}
for (const anchorTag of allAnchorTags) {
const slug = getLastPartOfUrl(anchorTag.href)
const slugPage = allPages?.find(page => {
return page.slug.indexOf(slug) >= 0
})
if (slugPage) {
}
}
}