Redesign the interface around Scan and Library, classify uncatalogued books from similar ones
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
308c0e1ed3
commit
6cec404e21
71 files changed
+8634
-1502
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import type { Book } from '../shared/types.ts';
|
||||
import { cardLines, formatCallNumber, parseCallNumber, withYear } from '../shared/callnumber.ts';
|
||||
import { cutterFor, mainEntry } from '../shared/cutter.ts';
|
||||
|
||||
/** A call number for `authors`/`title` that shelves next to `neighbour`: its class part, a new cutter, then the year. */
|
||||
export function composeNumber(neighbour: string, authors: string[], title: string, year: number | null): string | null {
|
||||
const cn = parseCallNumber(neighbour);
|
||||
if (!cn) return null;
|
||||
const classPart = parseCallNumber(cardLines(cn)[0]);
|
||||
const cutter = parseCallNumber(`A1 ${cutterFor(mainEntry(authors, title))}`)?.cutters[0];
|
||||
if (!classPart || !cutter) return null;
|
||||
const next = { ...classPart, cutters: [...classPart.cutters] };
|
||||
if (next.cutters.length < 3) next.cutters.push(cutter);
|
||||
return formatCallNumber(year ? withYear(next, year) : next);
|
||||
}
|
||||
|
||||
/** Up to `limit` of the library's books with a readable call number whose title or author matches. */
|
||||
export function findNeighbours(books: Book[], text: string, limit = 8): Book[] {
|
||||
const needle = text.trim().toLowerCase();
|
||||
if (!needle) return [];
|
||||
const out: Book[] = [];
|
||||
for (const b of books) {
|
||||
if (!b.callNumber || !parseCallNumber(b.callNumber)) continue;
|
||||
if ([b.title, b.authors.join(' ')].some(s => s.toLowerCase().includes(needle))) out.push(b);
|
||||
if (out.length >= limit) break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Reference in new issue
Block a user