diff --git a/packages/animegarden/src/garden.ts b/packages/animegarden/src/garden.ts index 4e431400..9b14095d 100644 --- a/packages/animegarden/src/garden.ts +++ b/packages/animegarden/src/garden.ts @@ -82,11 +82,15 @@ export async function fetchResources( } } return { - resources: [...map.values()].sort((lhs, rhs) => rhs.createdAt.localeCompare(lhs.createdAt)), + resources: uniq([...map.values()]), timestamp }; } else { - return fetchPage(options.page ?? 1); + const r = await fetchPage(options.page ?? 1); + return { + resources: uniq(r.resources), + timestamp: r.timestamp + }; } async function fetchPage(page: number) { @@ -121,6 +125,14 @@ export async function fetchResources( ); } } + + function uniq(resources: Resource[]) { + const map = new Map(); + for (const r of resources) { + map.set(r.href, r); + } + return [...map.values()].sort((lhs, rhs) => rhs.createdAt.localeCompare(lhs.createdAt)); + } } export async function fetchResourceDetail(