mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user