refactor: rename checkStartWithHttp to isHttpLink

- Update function name and implementation in utils/index.js
- Replace all occurrences in getPageProperties.js, post.js, and BlogPostCard.js
- Improve function documentation and use regex for better URL matching
This commit is contained in:
anime
2025-07-08 23:04:41 +08:00
parent 645edd7ead
commit b16512ac9a
4 changed files with 17 additions and 20 deletions

View File

@@ -89,19 +89,16 @@ export function isUrl(str) {
return false
}
return str?.indexOf('/') === 0 || checkStartWithHttp(str)
return str?.indexOf('/') === 0 || 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)
}
/**