Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ It is therefore imperative that you use [Content Security Policy (CSP)](https://
### The Main Interface for Books

Processors for each book format return an object that implements the following interface:
- `.type`: a string that identifies the book format.
- `.sections`: an array of sections in the book. Each item has the following properties:
- `.load()`: returns a string containing the URL that will be rendered. May be async.
- `.unload()`: returns nothing. If present, can be used to free the section.
Expand Down
1 change: 1 addition & 0 deletions fb2.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ const dataID = 'data-foliate-id'

export const makeFB2 = async blob => {
const book = {}

const doc = await parseXML(blob)
const converter = new FB2Converter(doc)

Expand Down
7 changes: 7 additions & 0 deletions view.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,46 @@ export const makeBook = async file => {
const loader = await makeDirectoryLoader(file)
const { EPUB } = await import('./epub.js')
book = await new EPUB(loader).init()
book.type = 'epub'
}
else if (!file.size) throw new NotFoundError('File not found')
else if (await isZip(file)) {
const loader = await makeZipLoader(file)
if (isCBZ(file)) {
const { makeComicBook } = await import('./comic-book.js')
book = makeComicBook(loader, file)
book.type = 'comic-book'
}
else if (isFBZ(file)) {
const { makeFB2 } = await import('./fb2.js')
const { entries } = loader
const entry = entries.find(entry => entry.filename.endsWith('.fb2'))
const blob = await loader.loadBlob((entry ?? entries[0]).filename)
book = await makeFB2(blob)
book.type = 'fb2'
}
else {
const { EPUB } = await import('./epub.js')
book = await new EPUB(loader).init()
book.type = 'epub'
}
}
else if (await isPDF(file)) {
const { makePDF } = await import('./pdf.js')
book = await makePDF(file)
book.type = 'pdf'
}
else {
const { isMOBI, MOBI } = await import('./mobi.js')
if (await isMOBI(file)) {
const fflate = await import('./vendor/fflate.js')
book = await new MOBI({ unzlib: fflate.unzlibSync }).open(file)
book.type = 'mobi'
}
else if (isFB2(file)) {
const { makeFB2 } = await import('./fb2.js')
book = await makeFB2(file)
book.type = 'fb2'
}
}
if (!book) throw new UnsupportedTypeError('File type not supported')
Expand Down