mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-04-02 16:44:56 +02:00
fix: deduplicate interactions by author+type+target, not just wm-id
Same interaction arriving from webmention.io and conversations API had different wm-id values but same author/type/target. Now normalizes URLs and deduplicates by semantic identity.
This commit is contained in:
@@ -515,12 +515,23 @@ function interactionsApp() {
|
||||
mergeAndDeduplicate(wmItems, convItems) {
|
||||
const convUrls = new Set(convItems.map(c => c.url).filter(Boolean));
|
||||
const seen = new Set();
|
||||
const seenInteraction = new Set();
|
||||
const result = [];
|
||||
|
||||
const normalizeUrl = (url) => (url || '').replace(/\/$/, '');
|
||||
const interactionKey = (item) => {
|
||||
const author = normalizeUrl(item.author?.url);
|
||||
const type = item['wm-property'] || '';
|
||||
const target = normalizeUrl(item['wm-target']);
|
||||
return `${author}|${type}|${target}`;
|
||||
};
|
||||
|
||||
for (const item of convItems) {
|
||||
const key = item['wm-id'] || item.url;
|
||||
if (key && !seen.has(key)) {
|
||||
const iKey = interactionKey(item);
|
||||
if (key && !seen.has(key) && !seenInteraction.has(iKey)) {
|
||||
seen.add(key);
|
||||
seenInteraction.add(iKey);
|
||||
result.push(item);
|
||||
}
|
||||
}
|
||||
@@ -530,12 +541,16 @@ function interactionsApp() {
|
||||
if (seen.has(wmKey)) continue;
|
||||
if (item.url && convUrls.has(item.url)) continue;
|
||||
|
||||
const iKey = interactionKey(item);
|
||||
if (seenInteraction.has(iKey)) continue;
|
||||
|
||||
if (!item.platform) {
|
||||
const detected = this.detectPlatform(item);
|
||||
if (detected) item.platform = detected;
|
||||
}
|
||||
|
||||
seen.add(wmKey);
|
||||
seenInteraction.add(iKey);
|
||||
result.push(item);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user