Build the EPUB Reader
22 min read
Track Book-Wide EPUB Locations
Track Book-Wide EPUB Locations
Task
Generate book-wide EPUB locations so progress is measured across the entire book rather than only within the current chapter.
After loading the book:
await book.ready;
await book.locations.generate(1600);
Convert a CFI to a percentage:
const percentage = book.locations.percentageFromCfi(cfi);
Convert a percentage back to a CFI:
const cfi = book.locations.cfiFromPercentage(percentage);
You can also obtain the location index:
const location = book.locations.locationFromCfi(cfi);
Do not use displayed.page / displayed.total as the book-wide progress value. Those numbers describe the current section/chapter rendering.
Persisting the resulting CFI is the job of Module 7.
Test
Navigate through multiple chapters and inspect the percentage produced from the current CFI.
Confirm the percentage changes across chapter boundaries.
Checkpoint
Readly now has the EPUB location data needed for true book-wide progress and resume behavior.