Skip to content

Commit f764d24

Browse files
committed
2 parents aa58c7c + 8688278 commit f764d24

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

components/ExternalPlugins.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const ExternalPlugin = props => {
165165
}
166166

167167
setTimeout(() => {
168-
// 映射url
168+
// 将notion-id格式的url转成自定义slug
169169
convertInnerUrl(props?.allNavPages)
170170
}, 500)
171171
}, [router])

lib/notion/convertInnerUrl.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { loadLangFromLocalStorage } from '@/lib/lang'
12
import { idToUuid } from 'notion-utils'
23
import { checkStrIsNotionId, getLastPartOfUrl, isBrowser } from '../utils'
3-
import { loadLangFromLocalStorage } from '@/lib/lang'
44

55
/**
66
* 处理页面内连接跳转:
@@ -13,12 +13,13 @@ export const convertInnerUrl = allPages => {
1313
}
1414
const allAnchorTags = document
1515
?.getElementById('notion-article')
16-
?.querySelectorAll('a.notion-link')
16+
?.querySelectorAll('a.notion-link, a.notion-collection-card')
1717

1818
if (!allAnchorTags) {
1919
return
2020
}
21-
const { origin, pathname } = window.location;
21+
22+
const { origin, pathname } = window.location
2223
const currentURL = origin + pathname
2324
const currentPathLang = pathname.split('/').filter(Boolean)[0]
2425
const lang = loadLangFromLocalStorage().split(/[-_]/)[0]
@@ -49,5 +50,18 @@ export const convertInnerUrl = allPages => {
4950
anchorTag.target = '_self'
5051
}
5152
}
53+
54+
// 如果链接以#号结尾,则强制在新窗口打开
55+
if (anchorTag.href.endsWith('#')) {
56+
anchorTag.target = '_blank'
57+
}
58+
}
59+
for (const anchorTag of allAnchorTags) {
60+
const slug = getLastPartOfUrl(anchorTag.href)
61+
const slugPage = allPages?.find(page => {
62+
return page.slug.indexOf(slug) >= 0
63+
})
64+
if (slugPage) {
65+
}
5266
}
53-
}
67+
}

0 commit comments

Comments
 (0)