fix: make post-navigation and webmentions sidebar widgets functional

Post navigation now uses previousInCollection/nextInCollection filters
to find adjacent posts (avoids Nunjucks loop scoping bug). Webmentions
sidebar widget now uses webmentionsForUrl and webmentionsByType filters
instead of non-existent filter function.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ricardo
2026-02-13 08:53:35 +01:00
parent cf3586eadd
commit a4c121d203
3 changed files with 43 additions and 22 deletions

View File

@@ -1,22 +1,26 @@
{# Post Navigation Widget - Previous/Next #}
{% if previousPost or nextPost %}
{# Uses previousInCollection/nextInCollection filters to find adjacent posts #}
{% set _prevPost = collections.posts | previousInCollection(page) %}
{% set _nextPost = collections.posts | nextInCollection(page) %}
{% if _prevPost or _nextPost %}
<div class="widget">
<h3 class="widget-title">More Posts</h3>
<div class="space-y-3">
{% if previousPost %}
{% if _prevPost %}
<div class="border-b border-surface-200 dark:border-surface-700 pb-3">
<span class="text-xs text-surface-500 uppercase tracking-wide block mb-1">Previous</span>
{% set _likedUrl = previousPost.data.likeOf or previousPost.data.like_of %}
{% set _bookmarkedUrl = previousPost.data.bookmarkOf or previousPost.data.bookmark_of %}
{% set _repostedUrl = previousPost.data.repostOf or previousPost.data.repost_of %}
{% set _replyToUrl = previousPost.data.inReplyTo or previousPost.data.in_reply_to %}
<a href="{{ previousPost.url }}" class="text-sm text-primary-600 dark:text-primary-400 hover:underline line-clamp-2 flex items-center gap-1.5">
{% set _likedUrl = _prevPost.data.likeOf or _prevPost.data.like_of %}
{% set _bookmarkedUrl = _prevPost.data.bookmarkOf or _prevPost.data.bookmark_of %}
{% set _repostedUrl = _prevPost.data.repostOf or _prevPost.data.repost_of %}
{% set _replyToUrl = _prevPost.data.inReplyTo or _prevPost.data.in_reply_to %}
<a href="{{ _prevPost.url }}" class="text-sm text-primary-600 dark:text-primary-400 hover:underline line-clamp-2 flex items-center gap-1.5">
{% if _likedUrl %}
<svg class="w-3.5 h-3.5 text-red-500 flex-shrink-0" fill="currentColor" viewBox="0 0 24 24"><path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/></svg>
Liked {{ _likedUrl | replace("https://", "") | truncate(35) }}
{% elif _bookmarkedUrl %}
<svg class="w-3.5 h-3.5 text-amber-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z"/></svg>
{{ previousPost.data.title or ("Bookmarked " + (_bookmarkedUrl | replace("https://", "") | truncate(30))) }}
{{ _prevPost.data.title or ("Bookmarked " + (_bookmarkedUrl | replace("https://", "") | truncate(30))) }}
{% elif _repostedUrl %}
<svg class="w-3.5 h-3.5 text-green-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg>
Reposted {{ _repostedUrl | replace("https://", "") | truncate(35) }}
@@ -24,25 +28,25 @@
<svg class="w-3.5 h-3.5 text-primary-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"/></svg>
Reply to {{ _replyToUrl | replace("https://", "") | truncate(35) }}
{% else %}
{{ previousPost.data.title or previousPost.data.name or (previousPost.templateContent | striptags | truncate(50)) or "Note" }}
{{ _prevPost.data.title or _prevPost.data.name or (_prevPost.templateContent | striptags | truncate(50)) or "Note" }}
{% endif %}
</a>
</div>
{% endif %}
{% if nextPost %}
{% if _nextPost %}
<div>
<span class="text-xs text-surface-500 uppercase tracking-wide block mb-1">Next</span>
{% set _likedUrl = nextPost.data.likeOf or nextPost.data.like_of %}
{% set _bookmarkedUrl = nextPost.data.bookmarkOf or nextPost.data.bookmark_of %}
{% set _repostedUrl = nextPost.data.repostOf or nextPost.data.repost_of %}
{% set _replyToUrl = nextPost.data.inReplyTo or nextPost.data.in_reply_to %}
<a href="{{ nextPost.url }}" class="text-sm text-primary-600 dark:text-primary-400 hover:underline line-clamp-2 flex items-center gap-1.5">
{% set _likedUrl = _nextPost.data.likeOf or _nextPost.data.like_of %}
{% set _bookmarkedUrl = _nextPost.data.bookmarkOf or _nextPost.data.bookmark_of %}
{% set _repostedUrl = _nextPost.data.repostOf or _nextPost.data.repost_of %}
{% set _replyToUrl = _nextPost.data.inReplyTo or _nextPost.data.in_reply_to %}
<a href="{{ _nextPost.url }}" class="text-sm text-primary-600 dark:text-primary-400 hover:underline line-clamp-2 flex items-center gap-1.5">
{% if _likedUrl %}
<svg class="w-3.5 h-3.5 text-red-500 flex-shrink-0" fill="currentColor" viewBox="0 0 24 24"><path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/></svg>
Liked {{ _likedUrl | replace("https://", "") | truncate(35) }}
{% elif _bookmarkedUrl %}
<svg class="w-3.5 h-3.5 text-amber-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z"/></svg>
{{ nextPost.data.title or ("Bookmarked " + (_bookmarkedUrl | replace("https://", "") | truncate(30))) }}
{{ _nextPost.data.title or ("Bookmarked " + (_bookmarkedUrl | replace("https://", "") | truncate(30))) }}
{% elif _repostedUrl %}
<svg class="w-3.5 h-3.5 text-green-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg>
Reposted {{ _repostedUrl | replace("https://", "") | truncate(35) }}
@@ -50,7 +54,7 @@
<svg class="w-3.5 h-3.5 text-primary-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"/></svg>
Reply to {{ _replyToUrl | replace("https://", "") | truncate(35) }}
{% else %}
{{ nextPost.data.title or nextPost.data.name or (nextPost.templateContent | striptags | truncate(50)) or "Note" }}
{{ _nextPost.data.title or _nextPost.data.name or (_nextPost.templateContent | striptags | truncate(50)) or "Note" }}
{% endif %}
</a>
</div>

View File

@@ -1,5 +1,6 @@
{# Webmentions Widget (if this post has any) #}
{% if webmentions and webmentions.length %}
{# Webmentions Sidebar Widget (compact counts for this post) #}
{% set _mentions = webmentions | webmentionsForUrl(page.url, urlAliases) %}
{% if _mentions and _mentions.length %}
<div class="widget">
<h3 class="widget-title flex items-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
@@ -8,9 +9,9 @@
Interactions
</h3>
<div class="space-y-2">
{% set likes = webmentions | filter("like-of") %}
{% set reposts = webmentions | filter("repost-of") %}
{% set replies = webmentions | filter("in-reply-to") %}
{% set likes = _mentions | webmentionsByType("likes") %}
{% set reposts = _mentions | webmentionsByType("reposts") %}
{% set replies = _mentions | webmentionsByType("replies") %}
{% if likes.length %}
<p class="text-sm text-surface-600 dark:text-surface-400">

View File

@@ -318,6 +318,22 @@ export default function (eleventyConfig) {
return mentions.filter((m) => m["wm-property"] === wmProperty);
});
// Post navigation — find previous/next post in a collection
// (Nunjucks {% set %} inside {% for %} doesn't propagate, so we need filters)
eleventyConfig.addFilter("previousInCollection", function (collection, page) {
if (!collection || !page) return null;
const index = collection.findIndex((p) => p.url === page.url);
return index > 0 ? collection[index - 1] : null;
});
eleventyConfig.addFilter("nextInCollection", function (collection, page) {
if (!collection || !page) return null;
const index = collection.findIndex((p) => p.url === page.url);
return index >= 0 && index < collection.length - 1
? collection[index + 1]
: null;
});
// Collections for different post types
// Note: content path is content/ due to symlink structure
// "posts" shows ALL content types combined