From 50cdeb3b6e769e3522278a8fbe3fd1bc33d55c2b Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Thu, 9 Apr 2026 12:32:22 +0200 Subject: [PATCH] =?UTF-8?q?=20ActivityFeed=20=E2=80=94=20replaced=20the=20?= =?UTF-8?q?{/if} + {formatDate(a.started_at)}{#if a.handle} · @{a.handle}{/if}

+

- {a.title} + {a.title}

{/if} - + {/each} diff --git a/site/src/lib/dataloader.ts b/site/src/lib/dataloader.ts index 53a3a0a..3933a59 100644 --- a/site/src/lib/dataloader.ts +++ b/site/src/lib/dataloader.ts @@ -79,14 +79,23 @@ async function resolveShards( const shardResults = await Promise.allSettled( index.shards.map(async shard => { const url = shard.url.startsWith('http') ? shard.url : `${base}${shard.url}`; + // Base URL of this shard's directory (e.g. "http://…/data/dave/_merged/") + const shardBase = url.substring(0, url.lastIndexOf('/') + 1); const sub = await fetchJSON(url); // Recursively resolve nested shards (e.g. user shard that itself paginates) const activities = await resolveShards(sub, url); - // Tag each activity with the handle declared in the shard entry - if (shard.handle) { - return activities.map(a => ({ ...a, handle: shard.handle })); - } - return activities; + // Rewrite relative detail_url / track_url to be absolute so they can be + // fetched correctly regardless of where the root index lives. + return activities.map(a => ({ + ...a, + ...(shard.handle ? { handle: shard.handle } : {}), + detail_url: a.detail_url && !a.detail_url.startsWith('http') + ? `${shardBase}${a.detail_url}` + : a.detail_url, + track_url: a.track_url && !a.track_url.startsWith('http') + ? `${shardBase}${a.track_url}` + : a.track_url, + })); }), ); @@ -152,7 +161,10 @@ export async function loadActivity( if (cached) return cached; try { - return await fetchJSON(`${baseUrl}data/${detailUrl}`); + const url = detailUrl.startsWith('http') + ? detailUrl + : `${baseUrl}data/${detailUrl}`; + return await fetchJSON(url); } catch { return null; } diff --git a/site/src/pages/activity/[id].astro b/site/src/pages/activity/[id].astro index d152a1e..36cb8d5 100644 --- a/site/src/pages/activity/[id].astro +++ b/site/src/pages/activity/[id].astro @@ -19,13 +19,26 @@ export async function getStaticPaths() { const root: BASIndex = JSON.parse(readFileSync(join(dataDir, 'index.json'), 'utf-8')); // Collect activities from root (single-user) or walk shards (multi-user) - function readActivities(indexPath: string): ActivitySummary[] { + function readActivities(indexPath: string, urlPrefix: string = ''): ActivitySummary[] { try { const idx: BASIndex = JSON.parse(readFileSync(indexPath, 'utf-8')); - const own = idx.activities ?? []; + const own = (idx.activities ?? []).map(a => + urlPrefix + ? { + ...a, + detail_url: a.detail_url && !a.detail_url.startsWith('http') ? `${urlPrefix}${a.detail_url}` : a.detail_url, + track_url: a.track_url && !a.track_url.startsWith('http') ? `${urlPrefix}${a.track_url}` : a.track_url, + } + : a + ); const fromShards = (idx.shards ?? []).flatMap(s => { const shardPath = join(dataDir, s.url); - return readActivities(shardPath); + // Prefix for activities read from this shard: path of the shard dir relative to dataDir + const shardDir = s.url.substring(0, s.url.lastIndexOf('/') + 1); + return readActivities(shardPath, shardDir).map(a => ({ + ...a, + ...(s.handle && !a.handle ? { handle: s.handle } : {}), + })); }); return [...own, ...fromShards]; } catch {