多语言微调

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

View File

@@ -13,6 +13,8 @@ export const MenuItemDrop = ({ link }) => {
<div
onMouseOver={() => changeShow(true)}
onMouseOut={() => changeShow(false)}>
{' '}
menu-link pl-2 pr-4 no-underline tracking-widest pb-1
{/* 不含子菜单 */}
{!hasSubMenu && (
<Link
@@ -22,7 +24,6 @@ export const MenuItemDrop = ({ link }) => {
{link?.icon && <i className={link?.icon} />} {link?.name}
</Link>
)}
{/* 含子菜单的按钮 */}
{hasSubMenu && (
<>
@@ -31,7 +32,6 @@ export const MenuItemDrop = ({ link }) => {
</div>
</>
)}
{/* 子菜单 */}
{hasSubMenu && (
<ul