diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index 571c1b8c..963607d1 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -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 diff --git a/lib/utils/index.js b/lib/utils/index.js index e12f2f85..fe49c942 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -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) {