内链自动替换

This commit is contained in:
tangly1024.com
2024-05-13 12:15:54 +08:00
parent b663d984ba
commit 622594a307

View File

@@ -12,13 +12,13 @@ export const mapPageUrl = allPages => {
const allAnchorTags = document.getElementsByTagName('a') // 或者使用 document.querySelectorAll('a') 获取 NodeList
for (const anchorTag of allAnchorTags) {
// 检查url
if (anchorTag.href) {
if (anchorTag?.href) {
// 如果url是一个Notion_id尝试匹配成博客的文章内链
const slug = getLastPartOfUrl(anchorTag.href)
if (checkStrIsNotionId(slug)) {
const slugPage = allPages.find(page => uuidToId(page.id) === slug)
const slugPage = allPages?.find(page => uuidToId(page.id) === slug)
if (slugPage) {
anchorTag.href = slugPage.href
anchorTag.href = slugPage?.href
}
}
}