refactor: rename canonical filter to canonicalize_url for better clarity

- Rename filter from 'canonical' to 'canonicalize_url' to follow Pongo2
naming conventions
- Update function name from filterCanonical to filterCanonicalizeURL
- Update template usage in post.html and profile.html
- Update test function name and all references
This commit is contained in:
Caidan Williams
2025-08-25 17:17:49 -07:00
parent 685650b296
commit eb45154823
4 changed files with 8 additions and 8 deletions
+2 -2
View File
@@ -7,10 +7,10 @@ import (
)
func init() {
pongo2.RegisterFilter("canonical", filterCanonical)
pongo2.RegisterFilter("canonicalize_url", filterCanonicalizeURL)
}
func filterCanonical(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
func filterCanonicalizeURL(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
urlStr := in.String()
parsedURL, err := url.Parse(urlStr)
+4 -4
View File
@@ -6,7 +6,7 @@ import (
"github.com/flosch/pongo2/v6"
)
func TestCanonicalFilter(t *testing.T) {
func TestCanonicalizeURLFilter(t *testing.T) {
tests := []struct {
name string
input string
@@ -47,14 +47,14 @@ func TestCanonicalFilter(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
inputValue := pongo2.AsValue(tt.input)
result, err := filterCanonical(inputValue, nil)
result, err := filterCanonicalizeURL(inputValue, nil)
if err != nil {
t.Errorf("filterCanonical() error = %v", err)
t.Errorf("filterCanonicalizeURL() error = %v", err)
return
}
if result.String() != tt.expected {
t.Errorf("filterCanonical() = %v, want %v", result.String(), tt.expected)
t.Errorf("filterCanonicalizeURL() = %v, want %v", result.String(), tt.expected)
}
})
}
+1 -1
View File
@@ -14,7 +14,7 @@
<meta property="profile:username" content="{{ profileView.Handle }}">
{%- if requestURI %}
<meta property="og:url" content="{{ requestURI }}">
<link rel="canonical" href="{{ requestURI|canonical }}" />
<link rel="canonical" href="{{ requestURI|canonicalize_url }}" />
{% endif -%}
{%- if postView.Author.DisplayName %}
<meta property="og:title" content="{{ postView.Author.DisplayName }} (@{{ postView.Author.Handle }})">
+1 -1
View File
@@ -15,7 +15,7 @@
<meta property="profile:username" content="{{ profileView.Handle }}">
{%- if requestURI %}
<meta property="og:url" content="{{ requestURI }}">
<link rel="canonical" href="{{ requestURI|canonical }}" />
<link rel="canonical" href="{{ requestURI|canonicalize_url }}" />
{% endif -%}
{%- if profileView.DisplayName %}
<meta property="og:title" content="{{ profileView.DisplayName }} (@{{ profileView.Handle }})">