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:
@@ -7,10 +7,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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()
|
urlStr := in.String()
|
||||||
|
|
||||||
parsedURL, err := url.Parse(urlStr)
|
parsedURL, err := url.Parse(urlStr)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/flosch/pongo2/v6"
|
"github.com/flosch/pongo2/v6"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCanonicalFilter(t *testing.T) {
|
func TestCanonicalizeURLFilter(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input string
|
input string
|
||||||
@@ -47,14 +47,14 @@ func TestCanonicalFilter(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
inputValue := pongo2.AsValue(tt.input)
|
inputValue := pongo2.AsValue(tt.input)
|
||||||
result, err := filterCanonical(inputValue, nil)
|
result, err := filterCanonicalizeURL(inputValue, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("filterCanonical() error = %v", err)
|
t.Errorf("filterCanonicalizeURL() error = %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.String() != tt.expected {
|
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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<meta property="profile:username" content="{{ profileView.Handle }}">
|
<meta property="profile:username" content="{{ profileView.Handle }}">
|
||||||
{%- if requestURI %}
|
{%- if requestURI %}
|
||||||
<meta property="og:url" content="{{ requestURI }}">
|
<meta property="og:url" content="{{ requestURI }}">
|
||||||
<link rel="canonical" href="{{ requestURI|canonical }}" />
|
<link rel="canonical" href="{{ requestURI|canonicalize_url }}" />
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{%- if postView.Author.DisplayName %}
|
{%- if postView.Author.DisplayName %}
|
||||||
<meta property="og:title" content="{{ postView.Author.DisplayName }} (@{{ postView.Author.Handle }})">
|
<meta property="og:title" content="{{ postView.Author.DisplayName }} (@{{ postView.Author.Handle }})">
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<meta property="profile:username" content="{{ profileView.Handle }}">
|
<meta property="profile:username" content="{{ profileView.Handle }}">
|
||||||
{%- if requestURI %}
|
{%- if requestURI %}
|
||||||
<meta property="og:url" content="{{ requestURI }}">
|
<meta property="og:url" content="{{ requestURI }}">
|
||||||
<link rel="canonical" href="{{ requestURI|canonical }}" />
|
<link rel="canonical" href="{{ requestURI|canonicalize_url }}" />
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{%- if profileView.DisplayName %}
|
{%- if profileView.DisplayName %}
|
||||||
<meta property="og:title" content="{{ profileView.DisplayName }} (@{{ profileView.Handle }})">
|
<meta property="og:title" content="{{ profileView.DisplayName }} (@{{ profileView.Handle }})">
|
||||||
|
|||||||
Reference in New Issue
Block a user