mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-04-02 16:44:56 +02:00
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:
@@ -21,24 +21,33 @@
|
||||
// Use server-side proxy to keep webmention.io token secure
|
||||
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)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
if (!data.children || !data.children.length) return;
|
||||
|
||||
// Filter to webmentions received after build time
|
||||
const newMentions = data.children.filter((wm) => {
|
||||
let mentionsToShow;
|
||||
if (hasBuildTimeSection) {
|
||||
// Build-time section exists - only show NEW webmentions to avoid duplicates
|
||||
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
|
||||
const likes = newMentions.filter((m) => m['wm-property'] === 'like-of');
|
||||
const reposts = newMentions.filter((m) => m['wm-property'] === 'repost-of');
|
||||
const replies = newMentions.filter((m) => m['wm-property'] === 'in-reply-to');
|
||||
const mentions = newMentions.filter((m) => m['wm-property'] === 'mention-of');
|
||||
const likes = mentionsToShow.filter((m) => m['wm-property'] === 'like-of');
|
||||
const reposts = mentionsToShow.filter((m) => m['wm-property'] === 'repost-of');
|
||||
const replies = mentionsToShow.filter((m) => m['wm-property'] === 'in-reply-to');
|
||||
const mentions = mentionsToShow.filter((m) => m['wm-property'] === 'mention-of');
|
||||
|
||||
// Append new likes
|
||||
if (likes.length) {
|
||||
|
||||
Reference in New Issue
Block a user