1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-09-19 20:02:10 +00:00

Render webmentions whose targets have fragments

If a target URL has a fragment, it should match against the page URL
even without the fragment.
This commit is contained in:
Rohan Kumar 2023-07-22 17:26:11 -07:00
parent 6391da4aa7
commit 6fc55df736
No known key found for this signature in database
GPG key ID: 1E892DB2A5F84479

View file

@ -17,7 +17,21 @@
{{- $oldTarget := $target | replaceRE "/posts" "" | replaceRE "/$" ".html" -}}
{{ $targets = (slice $target $oldTarget) }}
{{- end -}}
{{- $webmentions := where $allMentions "target" "in" $targets -}}
{{- /* 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 */ -}}
{{- $webmentions := slice -}}
{{- range $allMentions -}}
{{- if in $targets .target -}}
{{ $webmentions = $webmentions | append . }}
{{- else -}}
{{- $fragment := printf `#%s` (urls.Parse .target).Fragment -}}
{{- if gt (len $fragment) 1 -}}
{{- $trimmedTarget := strings.TrimSuffix $fragment .target -}}
{{- if in $targets $trimmedTarget -}}
{{ $webmentions = $webmentions | append . }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- /* Render webmentions if they exist */ -}}
{{- $count := (len $webmentions) -}}
{{- if gt $count 0 -}}