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