mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-05-15 06:58:50 +02:00
refactor: use dedicated webmentions proxy endpoint
Switch from /rssapi/api/webmentions to /webmentions-api/api/mentions for cleaner separation of concerns. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+46
-14
@@ -192,7 +192,7 @@ permalink: /interactions/
|
|||||||
|
|
||||||
{# Webmentions list #}
|
{# Webmentions list #}
|
||||||
<div x-show="!loading || webmentions.length" class="space-y-4">
|
<div x-show="!loading || webmentions.length" class="space-y-4">
|
||||||
<template x-for="wm in filteredWebmentions" :key="wm['wm-id']">
|
<template x-for="wm in paginatedWebmentions" :key="wm['wm-id']">
|
||||||
<div class="p-4 bg-surface-100 dark:bg-surface-800 rounded-lg">
|
<div class="p-4 bg-surface-100 dark:bg-surface-800 rounded-lg">
|
||||||
<div class="flex gap-3">
|
<div class="flex gap-3">
|
||||||
{# Author avatar #}
|
{# Author avatar #}
|
||||||
@@ -291,6 +291,7 @@ function interactionsApp() {
|
|||||||
page: 0,
|
page: 0,
|
||||||
perPage: 50,
|
perPage: 50,
|
||||||
hasMore: true,
|
hasMore: true,
|
||||||
|
refreshInterval: null,
|
||||||
|
|
||||||
get likes() {
|
get likes() {
|
||||||
return this.webmentions.filter(wm => wm['wm-property'] === 'like-of');
|
return this.webmentions.filter(wm => wm['wm-property'] === 'like-of');
|
||||||
@@ -317,34 +318,51 @@ function interactionsApp() {
|
|||||||
return this.webmentions.filter(wm => wm['wm-property'] === this.filterType);
|
return this.webmentions.filter(wm => wm['wm-property'] === this.filterType);
|
||||||
},
|
},
|
||||||
|
|
||||||
async init() {
|
get paginatedWebmentions() {
|
||||||
await this.fetchWebmentions();
|
// Client-side pagination of filtered results
|
||||||
|
return this.filteredWebmentions;
|
||||||
},
|
},
|
||||||
|
|
||||||
async fetchWebmentions(reset = true) {
|
async init() {
|
||||||
if (reset) {
|
await this.fetchWebmentions();
|
||||||
|
// Auto-refresh every 5 minutes
|
||||||
|
this.refreshInterval = setInterval(() => this.fetchWebmentions(true), 5 * 60 * 1000);
|
||||||
|
},
|
||||||
|
|
||||||
|
async fetchWebmentions(silent = false) {
|
||||||
|
if (!silent) {
|
||||||
|
this.loading = true;
|
||||||
this.page = 0;
|
this.page = 0;
|
||||||
this.webmentions = [];
|
this.webmentions = [];
|
||||||
this.hasMore = true;
|
this.hasMore = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loading = true;
|
|
||||||
this.error = null;
|
this.error = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const domain = '{{ site.webmentions.domain }}';
|
// Use our server-side proxy which has the token
|
||||||
const url = `https://webmention.io/api/mentions.jf2?domain=${domain}&per-page=${this.perPage}&page=${this.page}&sort-by=published&sort-dir=down`;
|
const url = `/webmentions-api/api/mentions?per-page=${this.perPage}&page=${this.page}`;
|
||||||
|
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
if (!response.ok) {
|
||||||
|
const data = await response.json().catch(() => ({}));
|
||||||
|
throw new Error(data.message || `HTTP ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const newMentions = data.children || [];
|
const newMentions = data.children || [];
|
||||||
|
|
||||||
if (reset) {
|
// Sort by published date, newest first
|
||||||
|
newMentions.sort((a, b) => {
|
||||||
|
const dateA = new Date(a.published || a['wm-received'] || 0);
|
||||||
|
const dateB = new Date(b.published || b['wm-received'] || 0);
|
||||||
|
return dateB - dateA;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (silent) {
|
||||||
|
// For silent refresh, replace all
|
||||||
this.webmentions = newMentions;
|
this.webmentions = newMentions;
|
||||||
} else {
|
} else {
|
||||||
this.webmentions = [...this.webmentions, ...newMentions];
|
this.webmentions = newMentions;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hasMore = newMentions.length === this.perPage;
|
this.hasMore = newMentions.length === this.perPage;
|
||||||
@@ -359,8 +377,22 @@ function interactionsApp() {
|
|||||||
async loadMore() {
|
async loadMore() {
|
||||||
this.loadingMore = true;
|
this.loadingMore = true;
|
||||||
this.page++;
|
this.page++;
|
||||||
await this.fetchWebmentions(false);
|
|
||||||
this.loadingMore = false;
|
try {
|
||||||
|
const url = `/webmentions-api/api/mentions?per-page=${this.perPage}&page=${this.page}`;
|
||||||
|
const response = await fetch(url);
|
||||||
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
const newMentions = data.children || [];
|
||||||
|
|
||||||
|
this.webmentions = [...this.webmentions, ...newMentions];
|
||||||
|
this.hasMore = newMentions.length === this.perPage;
|
||||||
|
} catch (err) {
|
||||||
|
this.error = `Failed to load more: ${err.message}`;
|
||||||
|
} finally {
|
||||||
|
this.loadingMore = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
formatDate(dateStr) {
|
formatDate(dateStr) {
|
||||||
|
|||||||
Reference in New Issue
Block a user