From f679c253a7dbdfba244634cc049865003865ac3f Mon Sep 17 00:00:00 2001 From: Vahagn Khachatryan Date: Fri, 11 Jan 2019 00:15:59 +0000 Subject: [PATCH] Adding title and css to xhtmls. --- src/epub.js | 33 +++++++++++++++++++++++++-------- src/sidebar.js | 16 ++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/epub.js b/src/epub.js index 3ad8a0b..a916d7b 100644 --- a/src/epub.js +++ b/src/epub.js @@ -52,14 +52,26 @@ class EpubXhtml{ let html = textDecoder.decode(content); let dom = domParser.parseFromString(html, 'text/html'); let xml = xmlSerializer.serializeToString(dom); -// let cnt = ` -// -let cnt = ` + + let css_link = '' + if (this.css) { + for (let i in this.css){ + css_link += ` \n` + } + } + + let title = '' + if (this.title) { + title = this.title + } + + let cnt = ` - + ${title} +${css_link} ${xml} @@ -229,15 +241,13 @@ class EpubMeta{ } addManifest(filename, mime){ - let key = filename if (mime && mime.startsWith('text/html')){ let o = new EpubXhtml(filename) - this.override[key] = o - filename = o.filename + this.override[filename] = o mime = o.mime } let id = 'id_' + filename.replace(/[^a-z0-9]/gi, '_').toLowerCase() - this.manifest[key] = + this.manifest[filename] = { filename : filename, mime : mime, @@ -245,6 +255,13 @@ class EpubMeta{ } } + addHtmlComponents(filename, title, css){ + if (filename in this.override){ + this.override[filename].title = title + this.override[filename].css = css + } + } + getId(filename){ return this.manifest[filename].id } diff --git a/src/sidebar.js b/src/sidebar.js index 19ca6b7..56830be 100644 --- a/src/sidebar.js +++ b/src/sidebar.js @@ -243,6 +243,20 @@ function fillManifest(epub, book) epub.meta.addCover(f.filename) } +function fillHtmlComponents(epub, book) +{ + for (let i in book.book_info.chapters){ + let url = book.book_info.chapters[i] + let chapter = book.chapter_info[url] + + css = [] + for (let i in chapter.stylesheets){ + css.push(chapter.stylesheets[i].full_path) + } + epub.meta.addHtmlComponents(chapter.full_path, chapter.title, css) + } +} + function fillToc(epub, book) { for (let i in book.book_toc){ @@ -278,6 +292,8 @@ function createEpub(book, epub){ // NCX and NAV files. fillToc(epub, book) + fillHtmlComponents(epub, book) + for (let url in book.book_files){ file = book.book_files[url] epub.addFile(file.filename, file.body)