feat(seo): add canonical URL filter to remove query parameters

Addresses community feedback about canonical URLs being misleading
when they include UTM parameters. The new Pongo2 filter creates
clean canonical URLs while preserving tracking parameters for
social sharing.
This commit is contained in:
Caidan Williams
2025-08-25 15:24:57 -07:00
parent 27c591f031
commit 60a1be6de0
+28
View File
@@ -0,0 +1,28 @@
package main
import (
"net/url"
"github.com/flosch/pongo2/v6"
)
func init() {
pongo2.RegisterFilter("canonical", filterCanonical)
}
func filterCanonical(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
urlStr := in.String()
parsedURL, err := url.Parse(urlStr)
if err != nil {
// If parsing fails, return the original URL
return in, nil
}
// Remove query parameters and fragment
parsedURL.RawQuery = ""
parsedURL.Fragment = ""
// Return the cleaned URL
return pongo2.AsValue(parsedURL.String()), nil
}