Omit SEO links for relative base URLs

portalOrigin fell back to the raw input when scheme or host
was missing, so paths like /fr/documents still produced
canonical and hreflang tags. Return an empty origin instead.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-07-21 19:08:55 +02:00
parent 59f053e8f9
commit 6024a2e803
2 changed files with 21 additions and 1 deletions

View File

@@ -76,10 +76,11 @@ func SEOFromRequest(r *http.Request, pageBaseURL string) (htmlLang, canonical st
// portalOrigin returns scheme://host from pageBaseURL, dropping any path,
// query, or fragment. Callers may pass a full request URL by mistake.
// Relative or malformed values yield "" so SEO links are omitted.
func portalOrigin(pageBaseURL string) string {
parsed, err := url.Parse(pageBaseURL)
if err != nil || parsed.Scheme == "" || parsed.Host == "" {
return strings.TrimRight(pageBaseURL, "/")
return ""
}
return (&url.URL{Scheme: parsed.Scheme, Host: parsed.Host}).String()