From 25367c55e76495be5ccce0074b46f4b3d2bb374b Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Fri, 17 Nov 2023 17:20:38 -0800 Subject: [PATCH] Remove extra target URL components for webmentions Remove query params, port numbers, bad schemes, anchors, etc. from webmention target URLs. --- layouts/partials/webmentions.html | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/layouts/partials/webmentions.html b/layouts/partials/webmentions.html index 4d11763..4a1ae6d 100644 --- a/layouts/partials/webmentions.html +++ b/layouts/partials/webmentions.html @@ -17,18 +17,16 @@ {{- $oldTarget := $target | replaceRE "/posts" "" | replaceRE "/$" ".html" -}} {{ $targets = (slice $target $oldTarget) }} {{- 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 -}} {{- 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 -}} + {{- $u := urls.Parse .target -}} + {{- $trimmedTarget := printf `https://%s%s` $u.Hostname $u.Path -}} + {{- if in $targets $trimmedTarget -}} + {{ $webmentions = $webmentions | append . }} {{- end -}} {{- end -}} {{- end -}}