mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-03 00:06:46 +01:00
Added a method to unwrap the chapter list
This commit is contained in:
parent
5778200c8f
commit
4229cb7fb6
@ -401,6 +401,26 @@ export default {
|
||||
this.chapters = tocTree
|
||||
})
|
||||
},
|
||||
flattenChapters(chapters) {
|
||||
// Convert the nested epub chapters into something that looks like audiobook chapters for player-ui
|
||||
const unwrap = (chapters) => {
|
||||
return chapters.reduce((acc, chapter) => {
|
||||
return chapter.subitems ? [...acc, chapter, ...unwrap(chapter.subitems)] : [...acc, chapter]
|
||||
}, [])
|
||||
}
|
||||
let flattenedChapters = unwrap(chapters)
|
||||
|
||||
flattenedChapters = flattenedChapters.sort((a, b) => a.start - b.start)
|
||||
for (let i = 0; i < flattenedChapters.length; i++) {
|
||||
flattenedChapters[i].id = i
|
||||
if (i < flattenedChapters.length - 1) {
|
||||
flattenedChapters[i].end = flattenedChapters[i + 1].start
|
||||
} else {
|
||||
flattenedChapters[i].end = 1
|
||||
}
|
||||
}
|
||||
return flattenedChapters
|
||||
},
|
||||
resize() {
|
||||
this.windowWidth = window.innerWidth
|
||||
this.windowHeight = window.innerHeight
|
||||
|
Loading…
Reference in New Issue
Block a user