Issue with chapters ordering in epub
I am facing an issue during the creation of the epub from book's chapters. My test book contains five chapters, two in the frontmatter, two in the body and one in the backmatter.
The issue is that during the conversion to epub the aforementioned order of the chapters breaks. After some research I've concluded that this issue is relating to the fragment's content. If one chapter contains significantly more content than other chapters and if that content is more complex (many custom tags which require conversion) then this chapter is placed in a lower order in the book (epub) which does not reflects its actual order.
It is my understanding that the problem lays in the below snippet of code and it has to do with the resolve order of these promises.
load (items) {
let counter = 0
return Promise.all(items.map(item => {
return this.parse(item.content).then($ => {
const id = `page-${++counter}`
const title = item.title || $('h1').text()
const target = `xhtml/${id}.xhtml`
this.xhtml.push({ id, $, title, target })
this.extract($)
})
}))
}