新增映射支持: url 前缀 %category%中文分类名映射成英文

This commit is contained in:
tangly1024.com
2024-05-13 11:36:53 +08:00
parent a5bab22409
commit c337c063be
2 changed files with 35 additions and 6 deletions

View File

@@ -61,6 +61,26 @@ export function sliceUrlFromHttp(str) {
}
}
/**
* 将相对路径的url test 转为绝对路径 /test
* 判断url如果不是以 /开头,则拼接一个 /
* 同时如果开头有重复的多个 // ,则只保留一个
* @param {*} str
*/
export function convertUrlStartWithOneSlash(str) {
if (!str) {
return '#'
}
// 判断url是否以 / 开头
if (!str.startsWith('/')) {
// 如果不是,则在前面拼接一个 /
str = '/' + str
}
// 移除开头的多个连续斜杠,只保留一个
str = str.replace(/\/+/g, '/')
return str
}
// 检查是否外链
export function checkContainHttp(str) {
// 检查字符串是否包含http