From 860bbee2b5a40610d780a8d2ff9621c5e05a1bb1 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Wed, 7 Oct 2026 03:44:31 -0500 Subject: [PATCH] diigo-cache: public list shows each bookmark's date first The list is in diigo's updated order; each item now leads with its updated_at as Date#toISOString() (diigo sends epoch seconds; updatedISO converts, tested), or "(no date)". Generated-by: Claude Opus 5.5 --- diigo-cache/src/index.ts | 6 ++++-- diigo-cache/src/items.ts | 8 ++++++++ diigo-cache/tests/caches.test.ts | 2 ++ diigo-cache/tests/items.test.ts | 13 ++++++++++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/diigo-cache/src/index.ts b/diigo-cache/src/index.ts index ea09df1..224da4d 100644 --- a/diigo-cache/src/index.ts +++ b/diigo-cache/src/index.ts @@ -15,7 +15,7 @@ import { WorkerEntrypoint } from "cloudflare:workers"; import { DiigoCache, PublicCache } from "./cache.js"; import type { Item } from "./cache.js"; -import { usernameOf } from "./items.js"; +import { updatedISO, usernameOf } from "./items.js"; import { toWebkey, idFromWebkey, isWebkey, shashKey } from "./webkeys.js"; import { pmSave } from "./pm-save.js"; @@ -457,7 +457,9 @@ ${items const title = typeof it.title === "string" && it.title ? it.title : url; const desc = typeof it.description === "string" && it.description ? `
${esc(it.description)}` : ""; const href = /^https?:\/\//i.test(url) ? url : "#"; - return `
  • ${esc(title)}${desc}
  • `; + const when = updatedISO(it); + const date = when ? `` : "(no date)"; + return `
  • ${date} ${esc(title)}${desc}
  • `; }) .join("\n")} `; diff --git a/diigo-cache/src/items.ts b/diigo-cache/src/items.ts index c78cdcc..10dac1f 100644 --- a/diigo-cache/src/items.ts +++ b/diigo-cache/src/items.ts @@ -64,3 +64,11 @@ export function usernameOf(item: Item | undefined): string { export function publicOnly(rows: ItemRow[]): ItemRow[] { return rows.filter((r) => !r.private); } + +/** when diigo last updated the item, as `Date#toISOString()`, or "" when + * it carries no usable `updated_at` (diigo sends epoch *seconds*) */ +export function updatedISO(item: Item): string { + const secs = item.updated_at; + if (typeof secs !== "number" || !Number.isFinite(secs)) return ""; + return new Date(secs * 1000).toISOString(); +} diff --git a/diigo-cache/tests/caches.test.ts b/diigo-cache/tests/caches.test.ts index 55523d0..b406de6 100644 --- a/diigo-cache/tests/caches.test.ts +++ b/diigo-cache/tests/caches.test.ts @@ -117,6 +117,8 @@ describe("worker routes", () => { const again = await (await call(`/public/${username}?page=2`)).text(); expect(again).toContain("cache: HIT"); expect(html).toContain("bookmark 25"); + // the date comes first, in toISOString() form + expect(html).toMatch(/