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:
1 parent
c9b2c2e8c9
commit
7ae1bcef0a
46 files changed
+8591
-545
No files matched your search
+17
-26
@@ -3,9 +3,8 @@ import { compareShelf } from '../shared/shelf.ts';
|
||||
import { join } from 'node:path';
|
||||
import { Hono } from 'hono';
|
||||
import type { Context } from 'hono';
|
||||
import type { Book, CardData, SearchResult, Settings } from '../shared/types.ts';
|
||||
import type { Book, CardData, Hierarchy, SearchResult, Settings } from '../shared/types.ts';
|
||||
import { normalizeIsbn } from '../shared/isbn.ts';
|
||||
import { parseCardCode } from '../shared/cardcode.ts';
|
||||
import { formatCallNumber, parseCallNumber, sortKeyOfRaw } from '../shared/callnumber.ts';
|
||||
import type { Db, Filter, NewBook } from './db.ts';
|
||||
import type { Jobs, ResolverLike } from './jobs.ts';
|
||||
@@ -15,6 +14,8 @@ import type { classNames } from '../shared/lcc-outline.ts';
|
||||
export type RenderCardsPdf = typeof renderCardsPdf;
|
||||
export type RenderCalibrationPdf = typeof renderCalibrationPdf;
|
||||
export type ClassNames = typeof classNames;
|
||||
/** The plain-word hierarchy of a call number and the book's stored tail (see hierarchy.ts). */
|
||||
export type HierarchyOf = (callNumber: string | null, tail: string[] | null) => Hierarchy;
|
||||
|
||||
export interface EventBus {
|
||||
on(listener: (event: string, data: unknown) => void): () => void;
|
||||
@@ -40,6 +41,8 @@ export interface AppDeps {
|
||||
db: Db; jobs: Jobs; resolver: ResolverLike;
|
||||
renderCardsPdf: RenderCardsPdf; renderCalibrationPdf: RenderCalibrationPdf;
|
||||
classNames: ClassNames;
|
||||
/** Defaults to the main class and subclass names alone (no outline ranges, no tail). */
|
||||
hierarchy?: HierarchyOf;
|
||||
events?: EventBus;
|
||||
/** Where pictures the scanner failed to read are kept for tuning (the newest 30). */
|
||||
capturesDir?: string;
|
||||
@@ -75,6 +78,11 @@ function cacheKeys(book: Book): string[] {
|
||||
|
||||
export function createApp(deps: AppDeps): Hono {
|
||||
const { db, jobs, resolver, classNames } = deps;
|
||||
const hierarchyOf: HierarchyOf = deps.hierarchy ?? ((callNumber) => {
|
||||
const cn = callNumber ? parseCallNumber(callNumber) : null;
|
||||
const names = classNames(cn?.letters ?? '');
|
||||
return { outline: [names.className, names.subclassName].filter((x): x is string => !!x), tail: [] };
|
||||
});
|
||||
const events = deps.events ?? createEventBus();
|
||||
const app = new Hono();
|
||||
|
||||
@@ -155,26 +163,6 @@ export function createApp(deps: AppDeps): Hono {
|
||||
return c.json({ book: addPending({ lccn, title: lccn }).book });
|
||||
});
|
||||
|
||||
// A card's QR code carries the whole record, so the book is made straight from it, with no lookup. It is not
|
||||
// queued for printing: it already has its card.
|
||||
app.post('/api/books/from-card', async (c) => {
|
||||
const text = (await body(c)).text;
|
||||
const card = typeof text === 'string' ? parseCardCode(text) : null;
|
||||
if (!card) throw new HttpError(400, 'Not a Booksorter card');
|
||||
const sortKey = sortKeyOfRaw(card.callNumber);
|
||||
const title = card.title.trim();
|
||||
const same = (b: Book) => b.title.trim().toLowerCase() === title.toLowerCase() && b.sortKey === sortKey;
|
||||
const existing = card.isbn13 ? db.findByIsbn(card.isbn13) : db.listBooks().find(same) ?? null;
|
||||
if (existing) return c.json({ book: existing, existed: true });
|
||||
const { book, created } = db.insertPending({
|
||||
isbn13: card.isbn13, title: title || card.callNumber, authors: card.authors, year: card.year,
|
||||
callNumber: card.callNumber, sortKey, confidence: card.approximate ? 'approximate' : 'exact', source: 'card',
|
||||
status: 'resolved', manualOverride: false, inQueue: false,
|
||||
});
|
||||
if (created) events.emitBook(book);
|
||||
return c.json({ book, existed: !created });
|
||||
});
|
||||
|
||||
app.get('/api/search', async (c) => {
|
||||
const title = c.req.query('title')?.trim() ?? '';
|
||||
const author = c.req.query('author')?.trim() ?? '';
|
||||
@@ -206,6 +194,12 @@ export function createApp(deps: AppDeps): Hono {
|
||||
return c.json({ book: addPending(fields).book });
|
||||
});
|
||||
|
||||
app.get('/api/books/:id/hierarchy', (c) => {
|
||||
const book = db.getBook(Number(c.req.param('id')));
|
||||
if (!book) throw new HttpError(404, 'No such book');
|
||||
return c.json(hierarchyOf(book.callNumber, book.hierarchyTail));
|
||||
});
|
||||
|
||||
app.get('/api/books', (c) => {
|
||||
const f = c.req.query('filter');
|
||||
const filter: Filter = f === 'queue' || f === 'attention' ? f : 'all';
|
||||
@@ -277,11 +271,8 @@ export function createApp(deps: AppDeps): Hono {
|
||||
.sort(compareShelf);
|
||||
if (!books.length) throw new HttpError(400, 'Nothing to print');
|
||||
const cards: CardData[] = books.map((b) => {
|
||||
const cn = parseCallNumber(b.callNumber!);
|
||||
const letters = cn?.letters ?? /^[A-Z]*/.exec(b.callNumber!)![0];
|
||||
const names = classNames(letters);
|
||||
return {
|
||||
callNumber: b.callNumber!, className: names.className, subclassName: names.subclassName,
|
||||
callNumber: b.callNumber!, hierarchy: hierarchyOf(b.callNumber, b.hierarchyTail),
|
||||
title: b.subtitle ? `${b.title}: ${b.subtitle}` : b.title, authors: b.authors, publisher: b.publisher, year: b.year,
|
||||
subjects: b.subjects, isbn13: b.isbn13, approximate: b.confidence === 'approximate',
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user