From 0f0a2304cb1bc6fb2c02e8637958b9be5f7f16a5 Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Wed, 16 Apr 2025 00:44:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E6=8C=81=E7=BB=AD=E7=A7=BB=E9=99=A4=20URL=20=E5=90=8E=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/url.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/util/url.go b/util/url.go index 88874c5..e6c7d39 100644 --- a/util/url.go +++ b/util/url.go @@ -55,12 +55,22 @@ func normalizeURL(rawURL string) string { // 将 http 和 https 视为同一种协议 u.Scheme = "https" - // 移除尾部的 /index.html 或 .html - u.Path = strings.TrimSuffix(u.Path, "/index.html") - u.Path = strings.TrimSuffix(u.Path, ".html") + // 使用循环持续移除后缀,直到Path不再变化 + for { + oldPath := u.Path - // 移除末尾的 / - u.Path = strings.TrimRight(u.Path, "/") + // 移除尾部的 /index.html 或 .html + 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() }