From f58198c02106bfc0dc32b3274e01a56ef9651d99 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Thu, 5 Feb 2026 10:06:40 +0100 Subject: [PATCH] fix: fetch webmentions for both trailing slash URL variants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bridgy sends webmentions with inconsistent target URLs — articles get trailing slashes but likes/bookmarks/reposts don't. The client-side JS now queries both variants and deduplicates, matching the build-time filter's behavior. Co-Authored-By: Claude Opus 4.5 --- js/webmentions.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/js/webmentions.js b/js/webmentions.js index 0cbb301..5eaa820 100644 --- a/js/webmentions.js +++ b/js/webmentions.js @@ -19,14 +19,31 @@ sessionStorage.setItem(cacheKey, '1'); // Use server-side proxy to keep webmention.io token secure - const apiUrl = `/webmentions-api/api/mentions?target=${encodeURIComponent(target)}&per-page=100`; + // Fetch both with and without trailing slash since webmention.io + // stores targets inconsistently (Bridgy sends different formats) + const targetWithSlash = target.endsWith('/') ? target : target + '/'; + const targetWithoutSlash = target.endsWith('/') ? target.slice(0, -1) : target; + const apiUrl1 = `/webmentions-api/api/mentions?target=${encodeURIComponent(targetWithSlash)}&per-page=100`; + const apiUrl2 = `/webmentions-api/api/mentions?target=${encodeURIComponent(targetWithoutSlash)}&per-page=100`; // Check if build-time webmentions section exists const hasBuildTimeSection = document.getElementById('webmentions') !== null; - fetch(apiUrl) - .then((res) => res.json()) - .then((data) => { + Promise.all([ + fetch(apiUrl1).then((res) => res.json()).catch(() => ({ children: [] })), + fetch(apiUrl2).then((res) => res.json()).catch(() => ({ children: [] })), + ]) + .then(([data1, data2]) => { + // Merge and deduplicate by wm-id + const seen = new Set(); + const allChildren = []; + for (const wm of [...(data1.children || []), ...(data2.children || [])]) { + if (!seen.has(wm['wm-id'])) { + seen.add(wm['wm-id']); + allChildren.push(wm); + } + } + const data = { children: allChildren }; if (!data.children || !data.children.length) return; let mentionsToShow;