fix: 使用循环持续移除 URL 后缀
This commit is contained in:
parent
20d82d485e
commit
0f0a2304cb
20
util/url.go
20
util/url.go
@ -55,12 +55,22 @@ func normalizeURL(rawURL string) string {
|
|||||||
// 将 http 和 https 视为同一种协议
|
// 将 http 和 https 视为同一种协议
|
||||||
u.Scheme = "https"
|
u.Scheme = "https"
|
||||||
|
|
||||||
// 移除尾部的 /index.html 或 .html
|
// 使用循环持续移除后缀,直到Path不再变化
|
||||||
u.Path = strings.TrimSuffix(u.Path, "/index.html")
|
for {
|
||||||
u.Path = strings.TrimSuffix(u.Path, ".html")
|
oldPath := u.Path
|
||||||
|
|
||||||
// 移除末尾的 /
|
// 移除尾部的 /index.html 或 .html
|
||||||
u.Path = strings.TrimRight(u.Path, "/")
|
u.Path = strings.TrimSuffix(u.Path, "/index.html")
|
||||||
|
u.Path = strings.TrimSuffix(u.Path, ".html")
|
||||||
|
|
||||||
|
// 移除末尾的 /
|
||||||
|
u.Path = strings.TrimRight(u.Path, "/")
|
||||||
|
|
||||||
|
// 如果路径不再变化,则退出循环
|
||||||
|
if oldPath == u.Path {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return u.String()
|
return u.String()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user