feat(web): book-detail annotations banner — ?loc= reader jumps, single/zip markdown export
Release / build-and-push (push) Successful in 3m9s

Objective 7 (web half). The 'Annotations' button slides a right-hand
banner (annotations_banner.templ + annotations-banner.ts) fed by the
existing per-book GET endpoints: friendly labels (Section N parsed from
the CFI spine / Page N from the PDF envelope / NN% + first-words
fallbacks), capped highlight previews, rich x-html expansion through the
objective-6 markdown pipeline, and per-row 'Open reader here' jumps
riding /readers/:uuid?loc= (consumeLocJump: jump outranks stored
progress for that open; URL stripped before sync can echo it). WEB-ONLY
export: single .md or one-file-per-item zip via fflate — item format
identical both modes ('# friendly label' / '# selection text' headers,
raw markdown bodies, no raw CFIs anywhere).

Verified live in Brave: 12 restored highlights + a markdown note
labeled/expanded correctly; the jump navigated, landed on the right
chapter and consumed ?loc=; export produced the 13-item .md (friendly
headers only) and a valid 13-entry zip. Book-detail's existing
recently-deleted modal stays untouched (banner is additive).
This commit is contained in:
John O'Keefe committed 2026-10-04 14:30:56 -04:00
1 parent 4b5e193d9f
commit 0b83db8fce
10 files changed
+1044 -483

No files matched your search

+33 -3
View File
@@ -934,12 +934,20 @@ document.addEventListener("alpine:init", () => {
this.handleKeydown(ev),
);
// Reading position comes from the database, fetched fresh at open
// (the rendered page carries no snapshot of it).
const saved = await this.fetchSavedLocation();
if (this.isFixedLayout && saved.page != null && saved.page > 0) {
// (the rendered page carries no snapshot of it) — UNLESS an
// annotations-banner jump handed one in via ?loc= (objective 7:
// the jump outranks the stored progress for this open only).
const savedLoc = await this.fetchSavedLocation();
const jump = this.consumeLocJump();
const saved = jump ?? savedLoc;
if (this.isFixedLayout && jump?.page != null) {
await this.view.init({ lastLocation: jump.page - 1 });
} else if (this.isFixedLayout && saved.page != null && saved.page > 0) {
// Fixed-layout & comics: a page index is the exact, universal locator.
// A bare number navigates directly to the section index in foliate.
await this.view.init({ lastLocation: saved.page - 1 })
} else if (jump?.cfi) {
await this.view.init({ lastLocation: jump.cfi })
} else if (saved.cfi) {
await this.view.init({ lastLocation: saved.cfi })
} else if (saved.percentage != null && saved.percentage > 0) {
@@ -2122,6 +2130,28 @@ document.addEventListener("alpine:init", () => {
return {};
}
},
/** ?loc= handoff from the book-detail annotations banner (objective 7):
* `cfi:<epubcfi>` or `page:<1-based>`; outranks the stored progress for
* this open only. Parsed once; consumed + stripped from the URL so a
* reload (or device sync / back navigation) restores normally. */
consumeLocJump(): { cfi?: string; page?: number } | null {
const params = new URLSearchParams(window.location.search);
const raw = params.get("loc");
if (!raw) return null;
params.delete("loc");
const qs = params.toString();
const base = window.location.pathname;
window.history.replaceState({}, "", base + (qs ? `?${qs}` : ""));
const value = decodeURIComponent(raw);
if (value.startsWith("cfi:")) {
return { cfi: value.slice(4) };
}
if (value.startsWith("page:")) {
const n = parseInt(value.slice(5), 10);
if (Number.isFinite(n) && n > 0) return { page: n };
}
return {};
},
debouncedSaveProgress(fraction: number, location: any, cfi: string) {
// Only an actual change from the last stored position writes
// progress: displaying a restored position must never overwrite a