Drop leftover /trust path prefix handling

Portals are host-routed on slug subdomains, so SEO path
stripping and the frontend basename helper were dead code.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-07-21 18:23:06 +02:00
parent 48c7585797
commit e4260d50d3
5 changed files with 26 additions and 78 deletions

View File

@@ -35,9 +35,14 @@ const defaultCompliancePortalLocale = "en"
// SEOFromRequest derives html lang, a self-referencing canonical URL, and
// hreflang alternates (including x-default → English) for the SPA shell.
// Portals are host-routed (slug subdomain / custom domain); the request path
// is already relative to the portal root.
func SEOFromRequest(r *http.Request, pageBaseURL string) (htmlLang, canonical string, hreflang []HreflangLink) {
appPath := complianceAppPath(r.URL.Path)
locale, rest := splitLocaleFromAppPath(appPath)
pathname := r.URL.Path
if pathname == "" {
pathname = "/"
}
locale, rest := splitLocaleFromAppPath(pathname)
htmlLang = locale
canonical = localizedPageURL(pageBaseURL, locale, rest)
@@ -57,26 +62,6 @@ func SEOFromRequest(r *http.Request, pageBaseURL string) (htmlLang, canonical st
return htmlLang, canonical, hreflang
}
// complianceAppPath returns the path relative to the portal root: under
// /trust/:slug it strips that prefix; on a custom domain it returns the path as-is.
func complianceAppPath(pathname string) string {
trimmed := strings.TrimPrefix(pathname, "/")
if strings.HasPrefix(trimmed, "trust/") {
parts := strings.SplitN(trimmed, "/", 3)
if len(parts) < 2 {
return "/"
}
if len(parts) == 2 {
return "/"
}
return "/" + parts[2]
}
if pathname == "" {
return "/"
}
return pathname
}
func splitLocaleFromAppPath(appPath string) (locale, rest string) {
segments := strings.Split(strings.Trim(appPath, "/"), "/")
if len(segments) == 0 || segments[0] == "" {
@@ -91,7 +76,7 @@ func splitLocaleFromAppPath(appPath string) (locale, rest string) {
return locale, "/" + strings.Join(segments[1:], "/")
}
// Unprefixed legacy path — treat content path as-is; default lang for tags.
// Unprefixed path — treat content path as-is; default lang for tags.
return defaultCompliancePortalLocale, appPath
}

View File

@@ -32,12 +32,19 @@ import (
func TestSEOFromRequest(t *testing.T) {
t.Parallel()
req, err := http.NewRequest(http.MethodGet, "https://app.example.com/trust/acme/fr/documents", nil)
req, err := http.NewRequest(
http.MethodGet,
"https://acme.probopage.localhost/fr/documents",
nil,
)
require.NoError(t, err)
lang, canonical, hreflang := complianceportal_v1.SEOFromRequest(req, "https://app.example.com/trust/acme")
lang, canonical, hreflang := complianceportal_v1.SEOFromRequest(
req,
"https://acme.probopage.localhost",
)
assert.Equal(t, "fr", lang)
assert.Equal(t, "https://app.example.com/trust/acme/fr/documents", canonical)
assert.Equal(t, "https://acme.probopage.localhost/fr/documents", canonical)
require.NotEmpty(t, hreflang)
var xDefault string
@@ -50,6 +57,6 @@ func TestSEOFromRequest(t *testing.T) {
enHref = link.Href
}
}
assert.Equal(t, "https://app.example.com/trust/acme/en/documents", enHref)
assert.Equal(t, "https://acme.probopage.localhost/en/documents", enHref)
assert.Equal(t, enHref, xDefault)
}