From a4c121d203b82f1179e4f1ab3dbb95b25b8fca98 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Fri, 13 Feb 2026 08:53:35 +0100 Subject: [PATCH] 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 --- .../components/widgets/post-navigation.njk | 38 ++++++++++--------- _includes/components/widgets/webmentions.njk | 11 +++--- eleventy.config.js | 16 ++++++++ 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/_includes/components/widgets/post-navigation.njk b/_includes/components/widgets/post-navigation.njk index 3bd08a8..c67f896 100644 --- a/_includes/components/widgets/post-navigation.njk +++ b/_includes/components/widgets/post-navigation.njk @@ -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 %}

More Posts

- {% if previousPost %} + {% if _prevPost %} {% endif %} - {% if nextPost %} + {% if _nextPost %}
Next - {% 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 %} - + {% 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 %} + {% if _likedUrl %} Liked {{ _likedUrl | replace("https://", "") | truncate(35) }} {% elif _bookmarkedUrl %} - {{ nextPost.data.title or ("Bookmarked " + (_bookmarkedUrl | replace("https://", "") | truncate(30))) }} + {{ _nextPost.data.title or ("Bookmarked " + (_bookmarkedUrl | replace("https://", "") | truncate(30))) }} {% elif _repostedUrl %} Reposted {{ _repostedUrl | replace("https://", "") | truncate(35) }} @@ -50,7 +54,7 @@ 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 %}
diff --git a/_includes/components/widgets/webmentions.njk b/_includes/components/widgets/webmentions.njk index 674d42f..d22e0d2 100644 --- a/_includes/components/widgets/webmentions.njk +++ b/_includes/components/widgets/webmentions.njk @@ -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 %}

@@ -8,9 +9,9 @@ Interactions

- {% 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 %}

diff --git a/eleventy.config.js b/eleventy.config.js index 6c8b15d..bbe41b2 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -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