feat: enhance mailto/tel link handling and streamline imports

- Introduced isMailOrTelLink utility function to validate mailto/tel links.
- Updated getPageProperties to properly handle mailto/tel links with target=_self, preventing unintended conversion to internal links by avoiding the addition of slashes.

Closes #3485
This commit is contained in:
anime
2025-07-08 22:59:08 +08:00
parent 5e6fa26c90
commit 645edd7ead
2 changed files with 15 additions and 6 deletions

View File

@@ -4,11 +4,7 @@ import formatDate from '../utils/formatDate'
// import { createHash } from 'crypto'
import md5 from 'js-md5'
import { siteConfig } from '../config'
import {
checkStartWithHttp,
convertUrlStartWithOneSlash,
getLastSegmentFromUrl
} from '../utils'
import { checkStartWithHttp, convertUrlStartWithOneSlash, getLastSegmentFromUrl, isMailOrTelLink } from '../utils'
import { extractLangPrefix } from '../utils/pageId'
import { mapImgUrl } from './mapImage'
import notionAPI from '@/lib/notion/getNotionAPI'
@@ -85,8 +81,9 @@ export default async function getPageProperties(
const fieldNames = BLOG.NOTION_PROPERTY_NAME
if (fieldNames) {
Object.keys(fieldNames).forEach(key => {
if (fieldNames[key] && properties[fieldNames[key]])
if (fieldNames[key] && properties[fieldNames[key]]) {
properties[key] = properties[fieldNames[key]]
}
})
}
@@ -193,6 +190,9 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
if (checkStartWithHttp(properties?.href)) {
properties.href = properties?.slug
properties.target = '_blank'
} else if (isMailOrTelLink(properties?.href)) {
properties.href = properties?.slug
properties.target = '_self'
} else {
properties.target = '_self'
// 伪静态路径右侧拼接.html

View File

@@ -104,6 +104,15 @@ export function checkStartWithHttp(str) {
}
}
/**
* 检查是否是邮件或电话链接
* @param href
* @returns {boolean}
*/
export function isMailOrTelLink(href) {
return /^(mailto:|tel:)/i.test(href)
}
// 检查一个字符串是否UUID https://ihateregex.io/expr/uuid/
export function checkStrIsUuid(str) {
if (!str) {