From 4c8c44a49eaa97ae61a937ec91eaaca1cd60ed7c Mon Sep 17 00:00:00 2001 From: Ricardo Date: Fri, 27 Feb 2026 16:17:16 +0100 Subject: [PATCH] feat: add save-for-later buttons to frontend pages Add shared save-later.js module and per-item save buttons to blogroll, podroll, listening, and news pages. Buttons are hidden by default and only visible when logged in. Posts to the readlater plugin API at /readlater/save. --- _includes/layouts/base.njk | 2 ++ blogroll.njk | 11 ++++++++ css/tailwind.css | 30 ++++++++++++++++++++++ js/save-later.js | 51 ++++++++++++++++++++++++++++++++++++++ listening.njk | 40 ++++++++++++++++++++++++++++++ news.njk | 33 ++++++++++++++++++++++++ podroll.njk | 11 ++++++++ 7 files changed, 178 insertions(+) create mode 100644 js/save-later.js diff --git a/_includes/layouts/base.njk b/_includes/layouts/base.njk index 5d47014..ee216e8 100644 --- a/_includes/layouts/base.njk +++ b/_includes/layouts/base.njk @@ -453,6 +453,8 @@ {# Admin auth detection - shows dashboard link + FAB when logged in #} + {# Save for Later buttons — active when logged in #} + {# Floating Action Button - visible only when logged in #}
Visit Blog +
diff --git a/css/tailwind.css b/css/tailwind.css index 43062db..91c8fd4 100644 --- a/css/tailwind.css +++ b/css/tailwind.css @@ -741,3 +741,33 @@ display: none; } } + +/* Save for Later buttons — hidden until auth confirmed */ +.save-later-btn { + display: none; +} + +body[data-indiekit-auth="true"] .save-later-btn { + display: inline-flex; + align-items: center; + gap: 4px; + cursor: pointer; + background: none; + border: 1px solid transparent; + border-radius: 6px; + padding: 2px 8px; + font-size: 0.75rem; + color: #6b7280; + transition: all 0.2s ease; +} + +body[data-indiekit-auth="true"] .save-later-btn:hover { + border-color: #d1d5db; + color: #4a9eff; +} + +.save-later--saved { + color: #4a9eff !important; + opacity: 0.6; + pointer-events: none; +} diff --git a/js/save-later.js b/js/save-later.js new file mode 100644 index 0000000..eff4f33 --- /dev/null +++ b/js/save-later.js @@ -0,0 +1,51 @@ +/** + * Save for Later — shared frontend module + * Handles save button clicks on blogroll, podroll, listening, and news pages. + * Only active when user is logged in (body[data-indiekit-auth="true"]). + */ +(function () { + function isLoggedIn() { + return document.body.getAttribute('data-indiekit-auth') === 'true'; + } + + async function saveForLater(button) { + var url = button.dataset.saveUrl; + var title = button.dataset.saveTitle || url; + var source = button.dataset.saveSource || 'manual'; + if (!url) return; + + button.disabled = true; + + try { + var response = await fetch('/readlater/save', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ url: url, title: title, source: source }), + credentials: 'same-origin' + }); + + if (response.ok) { + button.classList.add('save-later--saved'); + button.title = 'Saved'; + button.setAttribute('aria-label', 'Saved'); + var label = button.querySelector('.save-later-label'); + if (label) label.textContent = 'Saved'; + var icon = button.querySelector('.save-later-icon'); + if (icon) icon.textContent = '🔖'; + } else { + button.disabled = false; + } + } catch (e) { + button.disabled = false; + } + } + + document.addEventListener('click', function (e) { + if (!isLoggedIn()) return; + var button = e.target.closest('.save-later-btn'); + if (button) { + e.preventDefault(); + saveForLater(button); + } + }); +})(); diff --git a/listening.njk b/listening.njk index 2f9cfc4..3823fe4 100644 --- a/listening.njk +++ b/listening.njk @@ -295,6 +295,16 @@ withSidebar: true
Funkwhale {{ listening.relativeTime }} +
{% endfor %} @@ -333,6 +343,16 @@ withSidebar: true
Last.fm {{ scrobble.relativeTime }} +
{% endfor %} @@ -381,6 +401,16 @@ withSidebar: true + {% endfor %} @@ -424,6 +454,16 @@ withSidebar: true

{{ favorite.album }}

{% endif %} + {% endfor %} diff --git a/news.njk b/news.njk index b6fd6f6..f44b3b1 100644 --- a/news.njk +++ b/news.njk @@ -160,6 +160,17 @@ withSidebar: true + @@ -193,6 +204,17 @@ withSidebar: true + @@ -249,6 +271,17 @@ withSidebar: true +