Move non-linear items to the end of the book. Not all eReaders hide them, so this is an easy workaround

This commit is contained in:
daniel-j 2016-08-19 10:57:53 +02:00
parent e221235367
commit 5111f5ec32

View file

@ -77,6 +77,19 @@ export function createChapter (ch, html, callback) {
})
}
// some eReaders doesn't understand linear=no, so sort those items to the end of the spine/book.
function sortItemsLinear (a, b) {
let linearA = a.attrs.linear !== 'no'
let linearB = b.attrs.linear !== 'no'
if (linearA === linearB) {
return 0
} else if (linearA) {
return -1
} else {
return 1
}
}
export function createOpf (ffc) {
let remotes = []
ffc.remoteResources.forEach((r, url) => {
@ -128,7 +141,7 @@ export function createOpf (ffc) {
m('itemref', {idref: 'nav', linear: ffc.storyInfo.chapters.length <= 1 ? 'no' : undefined})
].concat(ffc.storyInfo.chapters.map((ch, num) =>
m('itemref', {idref: 'chapter_' + zeroFill(3, num + 1)})
))),
)).sort(sortItemsLinear)),
m('guide', [
m('reference', {type: 'cover', title: 'Cover', href: 'Text/cover.xhtml'}),