mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-04-02 16:44:56 +02:00
fix: filter out self-mentions from webmentions display
Owner replies sent via webmention-sender appear as webmentions on the owner's own posts, showing the reply as a top-level entry instead of threaded. Filter out any webmention whose source URL starts with the site URL, in both build-time (eleventy.config.js) and client-side (webmentions.js) rendering paths. Confab-Link: http://localhost:8080/sessions/184584f4-67e1-485a-aba8-02ac34a600fe
This commit is contained in:
@@ -13,6 +13,11 @@
|
||||
|
||||
if (!target || !domain) return;
|
||||
|
||||
// Extract site origin for filtering self-mentions
|
||||
// (owner replies sent via webmention-sender appear as webmentions on own posts)
|
||||
var siteOrigin = '';
|
||||
try { siteOrigin = new URL(target).origin; } catch(e) {}
|
||||
|
||||
// Use server-side proxy to keep webmention.io token secure
|
||||
// Fetch both with and without trailing slash since webmention.io
|
||||
// stores targets inconsistently (Bridgy sends different formats)
|
||||
@@ -55,6 +60,14 @@
|
||||
function processWebmentions(allChildren) {
|
||||
if (!allChildren || !allChildren.length) return;
|
||||
|
||||
// Filter out self-mentions (may exist in older cached data)
|
||||
allChildren = allChildren.filter(function(wm) {
|
||||
if (!siteOrigin) return true;
|
||||
var source = wm['wm-source'] || wm.url || '';
|
||||
return !source.startsWith(siteOrigin);
|
||||
});
|
||||
if (!allChildren.length) return;
|
||||
|
||||
let mentionsToShow;
|
||||
if (hasBuildTimeSection) {
|
||||
// Build-time section exists — deduplicate against what's actually rendered
|
||||
@@ -155,6 +168,13 @@
|
||||
const wmItems = [...(wmData1.children || []), ...(wmData2.children || [])];
|
||||
const convItems = [...(convData1.children || []), ...(convData2.children || [])];
|
||||
|
||||
// Filter out self-mentions (owner's own replies appearing as webmentions)
|
||||
function isSelfMention(wm) {
|
||||
if (!siteOrigin) return false;
|
||||
var source = wm['wm-source'] || wm.url || '';
|
||||
return source.startsWith(siteOrigin);
|
||||
}
|
||||
|
||||
// Build dedup sets from conversations items (richer metadata, take priority)
|
||||
const convUrls = new Set(convItems.map(c => c.url).filter(Boolean));
|
||||
const seen = new Set();
|
||||
@@ -162,6 +182,7 @@
|
||||
|
||||
// Add conversations items first (they have platform provenance)
|
||||
for (const wm of convItems) {
|
||||
if (isSelfMention(wm)) continue;
|
||||
const key = wm['wm-id'] || wm.url;
|
||||
if (key && !seen.has(key)) {
|
||||
seen.add(key);
|
||||
@@ -177,8 +198,9 @@
|
||||
if (authorUrl) authorActions.add(authorUrl + '::' + action);
|
||||
}
|
||||
|
||||
// Add webmention-io items, skipping duplicates
|
||||
// Add webmention-io items, skipping duplicates and self-mentions
|
||||
for (const wm of wmItems) {
|
||||
if (isSelfMention(wm)) continue;
|
||||
const key = wm['wm-id'];
|
||||
if (seen.has(key)) continue;
|
||||
// Also skip if same source URL exists in conversations
|
||||
|
||||
Reference in New Issue
Block a user