Skip to content

Commit a5e438f

Browse files
TMHSDigitalclaude
andcommitted
thumbs: logos already in manifest.shared count toward the three (#246); check-added compares UTC days (#247)
sharedImageIds takes the shared map as known records, so one new entry from a site whose logo was dropped earlier is dropped too. check-added reads the commit time as a UTC day, the clock new-entry writes added with, so an evening commit west of UTC no longer fails a correct entry. Closes #246 Closes #247 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LpkeXQPaUhxjgqdqnk6BrJ
1 parent 4adb944 commit a5e438f

5 files changed

Lines changed: 37 additions & 15 deletions

File tree

‎site/check-added.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ if (git(["rev-parse", "--is-shallow-repository"]).trim() === "true") {
2525
process.exit(0);
2626
}
2727

28-
const log = git(["log", "--reverse", "--format=%x00%as", "--name-status", "-M", "--diff-filter=AR", "--", "catalog"]);
28+
// %at, not %as: the author's local date is a day behind UTC in the evening
29+
// west of UTC, while `added` is written as a UTC date (#247).
30+
const log = git(["log", "--reverse", "--format=%x00%at", "--name-status", "-M", "--diff-filter=AR", "--", "catalog"]);
2931
const firstAdded = firstAddedFromLog(log);
3032
// Every entry file, parsed or not: a broken one still has an added date to check.
3133
const entries = readCatalog(path.join(ROOT, "catalog"), { root: ROOT }).map((r) => ({

‎site/lib/added-dates.mjs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99

1010
/**
1111
* Repo path => YYYY-MM-DD the file was first added, following renames, from
12-
* `git log --reverse --format=%x00%as --name-status -M --diff-filter=AR`
13-
* output (oldest commit first).
12+
* `git log --reverse --format=%x00%at --name-status -M --diff-filter=AR`
13+
* output (oldest commit first). A Unix timestamp header is read as a UTC
14+
* date, the same clock new-entry.mjs writes `added` with (#247); a
15+
* YYYY-MM-DD header is taken as is.
1416
*/
1517
export function firstAddedFromLog(out) {
1618
const first = new Map();
1719
let date = null;
1820
for (const raw of String(out).split("\n")) {
1921
if (raw.startsWith("\0")) {
20-
date = raw.slice(1).trim();
22+
date = commitDay(raw.slice(1).trim());
2123
continue;
2224
}
2325
const parts = raw.split("\t");
@@ -42,3 +44,8 @@ export function lateAddedDates(entries, firstAdded) {
4244
}
4345
return errors;
4446
}
47+
48+
/** "1730851200" (Unix seconds) => its UTC YYYY-MM-DD; anything else unchanged. */
49+
export function commitDay(token) {
50+
return /^\d+$/.test(token) ? new Date(Number(token) * 1000).toISOString().slice(0, 10) : token;
51+
}

‎site/lib/lib.test.mjs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,10 @@ eq("thumbs: twitter fallback", imageUrlFromHtml('<meta name="twitter:image" cont
11721172
eq("thumbs: no image", imageUrlFromHtml("<html></html>", "https://x/"), null);
11731173
eq("thumbs: shared hash dropped at three", [...sharedImageIds({ a: { hash: "h1" }, b: { hash: "h1" }, c: { hash: "h1" }, d: { hash: "h2" }, e: { hash: "h2" } })].sort().join(), "a,b,c");
11741174
eq("thumbs: pinned never dropped", [...sharedImageIds({ a: { hash: "h1", pinned: true }, b: { hash: "h1" }, c: { hash: "h1" }, d: { hash: "h1" } })].sort().join(), "b,c,d");
1175+
// #246: hashes already recorded in manifest.shared count toward the three.
1176+
eq("thumbs: one new record matching a known shared hash is dropped", [...sharedImageIds({ d: { hash: "h" }, e: { hash: "x" } }, { a: { hash: "h" }, b: { hash: "h" }, c: { hash: "h" } })].join(), "d");
1177+
eq("thumbs: known shared ids never returned", [...sharedImageIds({ d: { hash: "h" } }, { a: { hash: "h" }, b: { hash: "h" } })].sort().join(), "d");
1178+
eq("thumbs: a shared record for an id now in thumbs is not counted twice", [...sharedImageIds({ a: { hash: "h" } }, { a: { hash: "h" }, b: { hash: "h" } })].join(), "");
11751179
{
11761180
// #232: a run that re-drops the same shared images changes nothing.
11771181
const { manifestChanges } = await import("./thumbs.mjs");
@@ -1621,6 +1625,10 @@ eq("search: q from the URL is capped", readState(`?q=${"a".repeat(5000)}`, { q:
16211625
], first);
16221626
eq("added: a date reset by a move is caught", errs.length, 1);
16231627
has("added: the message names the right date", errs[0], "set added: 2026-07-19");
1628+
// #247: 2026-11-07T02:30Z is the evening of 11-06 in the Americas; the UTC day counts.
1629+
const utc = firstAddedFromLog(["\0" + String(Date.UTC(2026, 10, 7, 2, 30) / 1000), "", "A\tcatalog/2d/late.md"].join("\n"));
1630+
eq("added: a timestamp header is read as a UTC day", utc.get("catalog/2d/late.md"), "2026-11-07");
1631+
eq("added: a UTC added date on an evening commit passes", lateAddedDates([{ rel: "catalog/2d/late.md", added: "2026-11-07" }], utc).length, 0);
16241632
}
16251633

16261634
/* engine scope and limits on entry pages (#173) --------------------------- */

‎site/lib/thumbs.mjs‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,20 @@ export function imageUrlFromHtml(html, pageUrl) {
158158
}
159159
}
160160

161-
/** Ids whose image bytes are shared by three or more records: a logo, not a preview. Pinned records are exempt. */
162-
export function sharedImageIds(records) {
163-
const byHash = new Map();
164-
for (const [id, rec] of Object.entries(records || {})) {
165-
if (!rec || !rec.hash || rec.pinned) continue;
166-
if (!byHash.has(rec.hash)) byHash.set(rec.hash, []);
167-
byHash.get(rec.hash).push(id);
168-
}
161+
/**
162+
* Ids in `records` whose image bytes are shared by three or more records: a
163+
* logo, not a preview. `known` holds records already dropped as shared in an
164+
* earlier run; they count toward the three, so one new entry from a site
165+
* whose logo is on file is dropped too (#246). Pinned records are exempt.
166+
*/
167+
export function sharedImageIds(records, known = {}) {
168+
const count = new Map();
169+
const tally = (rec) => { if (rec && rec.hash && !rec.pinned) count.set(rec.hash, (count.get(rec.hash) || 0) + 1); };
170+
const own = Object.entries(records || {});
171+
for (const [, rec] of own) tally(rec);
172+
for (const [id, rec] of Object.entries(known || {})) if (!(records && id in records)) tally(rec);
169173
const out = new Set();
170-
for (const ids of byHash.values()) if (ids.length >= 3) for (const id of ids) out.add(id);
174+
for (const [id, rec] of own) if (rec && rec.hash && !rec.pinned && count.get(rec.hash) >= 3) out.add(id);
171175
return out;
172176
}
173177

‎site/thumbs.mjs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,9 @@ async function main() {
308308
CONCURRENCY
309309
);
310310

311-
// A hash shared by three or more entries is a logo, not a preview.
312-
for (const id of sharedImageIds(thumbs)) {
311+
// A hash shared by three or more entries is a logo, not a preview. Logos
312+
// dropped in earlier runs (in `shared`) count toward the three.
313+
for (const id of sharedImageIds(thumbs, shared)) {
313314
summary.dropped.push({ id, hash: thumbs[id].hash });
314315
shared[id] = thumbs[id];
315316
delete thumbs[id];

0 commit comments

Comments
 (0)