fix: show all webmentions when no build-time data exists
When build-time webmentions section doesn't exist, show ALL webmentions from the API instead of filtering to only new ones. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+19
-10
@@ -21,24 +21,33 @@
|
|||||||
// 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`;
|
const apiUrl = `/webmentions-api/api/mentions?target=${encodeURIComponent(target)}&per-page=100`;
|
||||||
|
|
||||||
|
// Check if build-time webmentions section exists
|
||||||
|
const hasBuildTimeSection = document.getElementById('webmentions') !== null;
|
||||||
|
|
||||||
fetch(apiUrl)
|
fetch(apiUrl)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data.children || !data.children.length) return;
|
if (!data.children || !data.children.length) return;
|
||||||
|
|
||||||
// Filter to webmentions received after build time
|
let mentionsToShow;
|
||||||
const newMentions = data.children.filter((wm) => {
|
if (hasBuildTimeSection) {
|
||||||
const wmTime = new Date(wm['wm-received']).getTime();
|
// Build-time section exists - only show NEW webmentions to avoid duplicates
|
||||||
return wmTime > buildTime;
|
mentionsToShow = data.children.filter((wm) => {
|
||||||
});
|
const wmTime = new Date(wm['wm-received']).getTime();
|
||||||
|
return wmTime > buildTime;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// No build-time section - show ALL webmentions from API
|
||||||
|
mentionsToShow = data.children;
|
||||||
|
}
|
||||||
|
|
||||||
if (!newMentions.length) return;
|
if (!mentionsToShow.length) return;
|
||||||
|
|
||||||
// Group by type
|
// Group by type
|
||||||
const likes = newMentions.filter((m) => m['wm-property'] === 'like-of');
|
const likes = mentionsToShow.filter((m) => m['wm-property'] === 'like-of');
|
||||||
const reposts = newMentions.filter((m) => m['wm-property'] === 'repost-of');
|
const reposts = mentionsToShow.filter((m) => m['wm-property'] === 'repost-of');
|
||||||
const replies = newMentions.filter((m) => m['wm-property'] === 'in-reply-to');
|
const replies = mentionsToShow.filter((m) => m['wm-property'] === 'in-reply-to');
|
||||||
const mentions = newMentions.filter((m) => m['wm-property'] === 'mention-of');
|
const mentions = mentionsToShow.filter((m) => m['wm-property'] === 'mention-of');
|
||||||
|
|
||||||
// Append new likes
|
// Append new likes
|
||||||
if (likes.length) {
|
if (likes.length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user