Print the subject hierarchy as a tree on cards, remove the QR code

Each card now shows, under the call number, the Library of Congress
outline levels for its class (from the published outline, down to the
narrowest range) followed by the place or topic from the catalogue
record's subject heading, one level per line. Existing books get the
subject part filled in by a background job at startup that changes
nothing else about them.

The QR code and everything that read it are removed; the subjects line
on the card is replaced by the tree.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-19 14:06:50 -07:00
1 parent c9b2c2e8c9
commit 7ae1bcef0a
46 files changed
+8591 -545

No files matched your search

+33 -3
View File
@@ -29,6 +29,13 @@ export interface ResolveOpts {
export interface Resolver {
resolve(input: ResolveInput, opts?: ResolveOpts): Promise<Resolution>;
search(title: string, author: string): Promise<SearchResult[]>;
/**
* Only the hierarchy tail of a book already in the library: the subject heading of its Library of Congress record
* (this edition's by ISBN, then by LCCN; with `viaTitle`, the title match the lookup itself would have used).
* Uses the same rate limit and cache as a lookup. [] when there is no record or no usable heading;
* throws TemporaryError when the catalogue cannot be asked.
*/
tail(input: { isbn13?: string; lccn?: string; title?: string; author?: string; viaTitle?: boolean }): Promise<string[]>;
}
type Partials = (Partial<BookMeta> | null | undefined)[];
@@ -247,20 +254,43 @@ export function createResolver(deps: {
const dewey = locRecs.map((r) => r.dewey).find(Boolean) ?? edition?.dewey ?? work?.dewey
?? locTitleRecs.map((r) => r.dewey).find(Boolean) ?? null;
// The tail comes from this edition's record, else the title-matched record. A number borrowed from similar
// books carries none. When the catalogue could not be asked it stays unknown (null) and is looked for later.
const tail: string[] | null = chosen?.source === 'similar' ? []
: locRecs[0] ? locRecs[0].subjectTail
: locTitleRecs[0] ? locTitleRecs[0].subjectTail
: locError ? null : [];
if (chosen) {
return {
meta, callNumber: chosen.callNumber, sortKey: chosen.sortKey,
confidence: chosen.confidence, source: chosen.source, dewey, reason: null,
confidence: chosen.confidence, source: chosen.source, dewey, tail, reason: null,
};
}
// Open Library had nothing and the LoC could not be asked: report that, not "no number found".
if (locError) throw locError;
if (olError) throw olError;
return {
meta, callNumber: null, sortKey: null, confidence: null, source: null, dewey,
meta, callNumber: null, sortKey: null, confidence: null, source: null, dewey, tail,
reason: meta ? 'No Library of Congress number found' : 'Not found in Open Library or the Library of Congress',
};
}
return { resolve, search: (title, author) => ol.search(title, author) };
async function tail(input: { isbn13?: string; lccn?: string; title?: string; author?: string; viaTitle?: boolean }): Promise<string[]> {
const isbn = input.isbn13 ? (normalizeIsbn(input.isbn13) ?? input.isbn13) : undefined;
let mine: MarcFields[] = [];
if (isbn) mine = await loc.byIsbn(isbn);
if (mine.length === 0 && input.lccn) {
// Same edition only if the book has no ISBN or the record lists this ISBN.
mine = (await loc.byLccn(input.lccn)).filter((r) => !isbn || r.isbns.includes(isbn));
}
if (mine[0]) return mine[0].subjectTail;
if (input.viaTitle && input.title && input.author) {
const found = (await loc.byTitle(input.title, input.author)).filter((r) => recordMatches(r, input.title!, input.author!));
if (found[0]) return found[0].subjectTail;
}
return [];
}
return { resolve, tail, search: (title, author) => ol.search(title, author) };
}