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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user