From 20e4403b0015626c90feaa3f3decebe67668e2af Mon Sep 17 00:00:00 2001 From: svemagie <869694+svemagie@users.noreply.github.com> Date: Sat, 21 Mar 2026 16:38:56 +0100 Subject: [PATCH] feat(listening): merge Funkwhale and Last.fm into single sorted timeline Adds a `mergeListens` Eleventy filter that combines both sources into one array sorted newest-first by timestamp (listenedAt / scrobbledAt). The Recent Listens section now renders a unified chronological feed with per-source badges and Alpine filter tabs still working. Co-Authored-By: Claude Sonnet 4.6 --- eleventy.config.js | 15 ++++ listening.njk | 169 ++++++++++++++++----------------------------- 2 files changed, 73 insertions(+), 111 deletions(-) diff --git a/eleventy.config.js b/eleventy.config.js index dd9b899..b9bcadf 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -670,6 +670,21 @@ export default function (eleventyConfig) { return array.slice(0, n); }); + // Merge Funkwhale listenings and Last.fm scrobbles into a single sorted timeline + eleventyConfig.addFilter("mergeListens", (listenings, scrobbles) => { + const fw = (listenings || []).map((l) => ({ + ...l, + _source: "funkwhale", + _ts: new Date(l.listenedAt || l.creation_date || l.listened_at || 0).getTime(), + })); + const lfm = (scrobbles || []).map((s) => ({ + ...s, + _source: "lastfm", + _ts: new Date(s.scrobbledAt || 0).getTime(), + })); + return [...fw, ...lfm].sort((a, b) => b._ts - a._ts); + }); + // Slugify filter eleventyConfig.addFilter("slugify", (str) => { if (!str) return ""; diff --git a/listening.njk b/listening.njk index 7c1daa4..3cb3f3a 100644 --- a/listening.njk +++ b/listening.njk @@ -265,122 +265,69 @@ withSidebar: true Recent Listens + {% set combinedListens = funkwhaleActivity.listenings | mergeListens(lastfmActivity.scrobbles) | head(20) %} +
- {# Funkwhale Listenings #} - {% if funkwhaleActivity.listenings.length %} -
- {% for listening in funkwhaleActivity.listenings | head(10) %} -
- {% if listening.coverUrl %} - - {% else %} -
- - - -
- {% endif %} - -
-

- {% if listening.trackUrl %} - {{ listening.track }} - {% else %} - {{ listening.track }} - {% endif %} - {% if listening.favorite %} - - {% endif %} -

-

{{ listening.artist }}

-
- -
- Funkwhale - {{ listening.relativeTime }} - - -
+ {% if combinedListens.length %} + {% for item in combinedListens %} +
+ {% if item.coverUrl %} + + {% else %} +
+ + +
- {% endfor %} -
- {% endif %} + {% endif %} - {# Last.fm Scrobbles #} - {% if lastfmActivity.scrobbles.length %} -
- {% for scrobble in lastfmActivity.scrobbles | head(10) %} -
- {% if scrobble.coverUrl %} - - {% else %} -
- - - -
- {% endif %} - -
-

- {% if scrobble.trackUrl %} - {{ scrobble.track }} - {% else %} - {{ scrobble.track }} - {% endif %} - {% if scrobble.loved %} - - {% endif %} -

-

{{ scrobble.artist }}

-
- -
- Last.fm - {{ scrobble.relativeTime }} - - -
+
+

+ {% if item.trackUrl %} + {{ item.track }} + {% else %} + {{ item.track }} + {% endif %} + {% if item.favorite or item.loved %} + + {% endif %} +

+

{{ item.artist }}

- {% endfor %} -
- {% endif %} - {% if not funkwhaleActivity.listenings.length and not lastfmActivity.scrobbles.length %} +
+ {% if item._source == 'funkwhale' %} + Funkwhale + {% else %} + Last.fm + {% endif %} + {{ item.relativeTime }} + + +
+
+ {% endfor %} + {% else %}

No recent listening history available.

{% endif %}