mirror of
https://git.sr.ht/~seirdy/seirdy.one
synced 2024-11-10 00:12:09 +00:00
Remove extra target URL components for webmentions
Remove query params, port numbers, bad schemes, anchors, etc. from webmention target URLs.
This commit is contained in:
parent
66b6ac0dbc
commit
25367c55e7
1 changed files with 5 additions and 7 deletions
|
@ -17,21 +17,19 @@
|
||||||
{{- $oldTarget := $target | replaceRE "/posts" "" | replaceRE "/$" ".html" -}}
|
{{- $oldTarget := $target | replaceRE "/posts" "" | replaceRE "/$" ".html" -}}
|
||||||
{{ $targets = (slice $target $oldTarget) }}
|
{{ $targets = (slice $target $oldTarget) }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- /* We can't just use a simple "where" function because we need to ignore URL anchors when making a comparison: https://discourse.gohugo.io/t/add-like-comparison-operator-to-the-where-function/42013/4 */ -}}
|
{{- /* We can't just use a simple "where" function because we need to ignore URL anchors/query-params when making a comparison: https://discourse.gohugo.io/t/add-like-comparison-operator-to-the-where-function/42013/4 */ -}}
|
||||||
{{- $webmentions := slice -}}
|
{{- $webmentions := slice -}}
|
||||||
{{- range $allMentions -}}
|
{{- range $allMentions -}}
|
||||||
{{- if in $targets .target -}}
|
{{- if in $targets .target -}}
|
||||||
{{ $webmentions = $webmentions | append . }}
|
{{ $webmentions = $webmentions | append . }}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
{{- $fragment := printf `#%s` (urls.Parse .target).Fragment -}}
|
{{- $u := urls.Parse .target -}}
|
||||||
{{- if gt (len $fragment) 1 -}}
|
{{- $trimmedTarget := printf `https://%s%s` $u.Hostname $u.Path -}}
|
||||||
{{- $trimmedTarget := strings.TrimSuffix $fragment .target -}}
|
|
||||||
{{- if in $targets $trimmedTarget -}}
|
{{- if in $targets $trimmedTarget -}}
|
||||||
{{ $webmentions = $webmentions | append . }}
|
{{ $webmentions = $webmentions | append . }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
|
||||||
{{- /* Render webmentions if they exist */ -}}
|
{{- /* Render webmentions if they exist */ -}}
|
||||||
{{- $count := (len $webmentions) -}}
|
{{- $count := (len $webmentions) -}}
|
||||||
{{- if gt $count 0 -}}
|
{{- if gt $count 0 -}}
|
||||||
|
|
Loading…
Reference in a new issue