Merge branch 'main' into feat/post/extract-page-content

This commit is contained in:
tangly1024
2025-07-27 21:23:37 +08:00
committed by GitHub
350 changed files with 1613 additions and 1456 deletions

View File

@@ -80,28 +80,31 @@ export function convertUrlStartWithOneSlash(str) {
}
/**
* 是否是一个相对或绝对路径的ur类
* @param {*} str
* @returns
* 判断是否是一个“URL 样式”的路径(内部或外部)
* 内部如 /about外部如 http://xxx.com
* @param str
* @returns {boolean}
*/
export function isUrl(str) {
if (!str) {
return false
}
return str?.indexOf('/') === 0 || checkStartWithHttp(str)
export function isUrlLikePath(str) {
return typeof str === 'string' && (str.startsWith('/') || isHttpLink(str))
}
// 检查是否外链
export function checkStartWithHttp(str) {
// 检查字符串是否包含http
if (str?.indexOf('http:') === 0 || str?.indexOf('https:') === 0) {
// 如果包含找到http的位置
return true
} else {
// 不包含
return false
}
/**
* 判断是否是 http(s) 开头的链接(外部网页)
* @param str
* @returns {boolean}
*/
export function isHttpLink(str) {
return typeof str === 'string' && /^https?:\/\//i.test(str)
}
/**
* 检查是否是邮件或电话链接
* @param href
* @returns {boolean}
*/
export function isMailOrTelLink(href) {
return /^(mailto:|tel:)/i.test(href)
}
// 检查一个字符串是否UUID https://ihateregex.io/expr/uuid/

View File

@@ -1,7 +1,7 @@
/**
* 文章相关工具
*/
import { checkStartWithHttp } from '.'
import { isHttpLink } from '.'
import { getPostBlocks } from '@/lib/db/getSiteData'
import { getPageTableOfContents } from '@/lib/notion/getPageTableOfContents'
import { siteConfig } from '@/lib/config'
@@ -59,7 +59,7 @@ export function checkSlugHasNoSlash(row) {
}
return (
(slug.match(/\//g) || []).length === 0 &&
!checkStartWithHttp(slug) &&
!isHttpLink(slug) &&
row.type.indexOf('Menu') < 0
)
}
@@ -76,7 +76,7 @@ export function checkSlugHasOneSlash(row) {
}
return (
(slug.match(/\//g) || []).length === 1 &&
!checkStartWithHttp(slug) &&
!isHttpLink(slug) &&
row.type.indexOf('Menu') < 0
)
}
@@ -94,7 +94,7 @@ export function checkSlugHasMorThanTwoSlash(row) {
return (
(slug.match(/\//g) || []).length >= 2 &&
row.type.indexOf('Menu') < 0 &&
!checkStartWithHttp(slug)
!isHttpLink(slug)
)
}