From ddf4906882f4bea473964e5b0d209cc3a33bddef Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 11 Jun 2012 01:40:15 +0300 Subject: beta 2012.06.11 00:21 --- scripts/context/lua/mtx-context.lua | 1 + scripts/context/lua/mtx-epub.lua | 53 +++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua index 3aff2bee2..890c7455c 100644 --- a/scripts/context/lua/mtx-context.lua +++ b/scripts/context/lua/mtx-context.lua @@ -258,6 +258,7 @@ function ctxrunner.checkfile(ctxdata,ctxname,defaultname) local flags = ctxdata.flags for e in xml.collected(xmldata,"/ctx:job/ctx:flags/ctx:flag") do + local flag = xml.text(e) or "" local key, value = match(flag,"^(.-)=(.+)$") if key and value then flags[key] = value diff --git a/scripts/context/lua/mtx-epub.lua b/scripts/context/lua/mtx-epub.lua index 6b7f7e718..52a144c20 100644 --- a/scripts/context/lua/mtx-epub.lua +++ b/scripts/context/lua/mtx-epub.lua @@ -63,6 +63,7 @@ local package = [[ urn:uuid:%s %s %s + @@ -70,6 +71,7 @@ local package = [[ + @@ -108,6 +110,23 @@ local toc = [[ ]] +local coverxhtml = [[ + + + + + + + cover.xhtml + + +
+ The cover image +
+ + +]] + -- We need to figure out what is permitted. Numbers only seem to give -- problems is some applications as do names with dashes. Also the -- optional toc is supposed to be there and although id's are by @@ -128,6 +147,7 @@ local mimetypes = { png = "image/png", jpg = "image/jpeg", ncx = "application/x-dtbncx+xml", + gif = "image/gif", -- default = "text/plain", } @@ -202,10 +222,10 @@ function scripts.epub.make() -- identifier = gsub(identifier,"[^a-zA-z0-9]","") - if firstpage == "" then + if firstpage ~= "" then images[firstpage] = firstpage end - if lastpage == "" then + if lastpage ~= "" then images[lastpage] = lastpage end @@ -216,6 +236,7 @@ function scripts.epub.make() local epubfile = file.replacesuffix(name,"epub") local epubroot = file.replacesuffix(name,"opf") local epubtoc = "toc.ncx" + local epubcover = "cover.xhtml" application.report("creating paths in tree %s",epubpath) lfs.mkdir(epubpath) @@ -236,6 +257,7 @@ function scripts.epub.make() end end + copyone("cover.xhtml") copyone("toc.ncx") local function copythem(files) @@ -264,14 +286,35 @@ function scripts.epub.make() local idmaker = idmakers[file.extname(root)] or idmakers.default - container = format(container,epubroot) - package = format(package,identifier,title,language,identifier,os.uuid(),creator,os.date("!%Y-%m-%dT%H:%M:%SZ"),concat(used,"\n"),idmaker(root)) - toc = format(toc,identifier,title,root) + container = format(container, + epubroot + ) + package = format(package, + identifier, + title, + language, + identifier, + os.uuid(), + creator, + os.date("!%Y-%m-%dT%H:%M:%SZ"), + idmaker(firstpage), + concat(used,"\n"), + idmaker(root) + ) + toc = format(toc, + identifier, + title, + root + ) + coverxhtml = format(coverxhtml, + firstpage + ) io.savedata(file.join(epubpath,"mimetype"),mimetype) io.savedata(file.join(epubpath,"META-INF","container.xml"),container) io.savedata(file.join(epubpath,"OEBPS",epubroot),package) io.savedata(file.join(epubpath,"OEBPS",epubtoc),toc) + io.savedata(file.join(epubpath,"OEBPS",epubcover),coverxhtml) application.report("creating archive\n\n") -- cgit v1.2.3