fix: fetch webmentions for both trailing slash URL variants
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 <noreply@anthropic.com>
This commit is contained in:
+21
-4
@@ -19,14 +19,31 @@
|
|||||||
sessionStorage.setItem(cacheKey, '1');
|
sessionStorage.setItem(cacheKey, '1');
|
||||||
|
|
||||||
// Use server-side proxy to keep webmention.io token secure
|
// 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
|
// Check if build-time webmentions section exists
|
||||||
const hasBuildTimeSection = document.getElementById('webmentions') !== null;
|
const hasBuildTimeSection = document.getElementById('webmentions') !== null;
|
||||||
|
|
||||||
fetch(apiUrl)
|
Promise.all([
|
||||||
.then((res) => res.json())
|
fetch(apiUrl1).then((res) => res.json()).catch(() => ({ children: [] })),
|
||||||
.then((data) => {
|
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;
|
if (!data.children || !data.children.length) return;
|
||||||
|
|
||||||
let mentionsToShow;
|
let mentionsToShow;
|
||||||
|
|||||||
Reference in New Issue
Block a user