Skip to content

Commit

Permalink
Make unviewable page URI configurable via options
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrini committed Sep 11, 2024
1 parent b314ea1 commit 9b49a04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/BookReader/BookModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import { clamp } from './utils.js';
/** @typedef {import('./options.js').PageData} PageData */
/** @typedef {import('../BookReader.js').default} BookReader */

// URI to display when a page is not viewable.
// TODO Render configurable html for the user instead.
// FIXME Don't reference files on archive.org
const UNVIEWABLE_PAGE_URI = '/bookreader/static/preview-default.png';

/**
* Contains information about the Book/Document independent of the way it is
* being rendering. Nothing here should reference e.g. the mode, zoom, etc.
Expand Down Expand Up @@ -160,7 +155,17 @@ export class BookModel {
*/
// eslint-disable-next-line no-unused-vars
getPageURI(index, reduce, rotate) {
return !this.getPageProp(index, 'viewable', true) ? UNVIEWABLE_PAGE_URI : this.getPageProp(index, 'uri');
if (!this.getPageProp(index, 'viewable', true)) {
const uri = this.br.options.unviewablePageURI;
if (uri.startsWith('.')) {
// It's a relative path, so make it relative to the images path
return this.br.options.imagesBaseURL + uri;
} else {
return uri;
}
} else {
return this.getPageProp(index, 'uri');
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/BookReader/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@ export const DEFAULT_OPTIONS = {
* On init, by default, we want to use srcSet for images
*/
useSrcSet: false,

/**
* @type {string}
* Path to the image to display when a page is unviewable (i.e. when
* displaying a preview of a book).
*
* Relative to the imagesBaseURL if a relative path is specified.
*/
unviewablePageURI: './unviewable_page.png',
};

/**
Expand Down
Binary file added src/assets/images/unviewable_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9b49a04

Please sign in to comment.