summaryrefslogtreecommitdiff
path: root/scripts/context
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-06-11 01:40:15 +0300
committerMarius <mariausol@gmail.com>2012-06-11 01:40:15 +0300
commitddf4906882f4bea473964e5b0d209cc3a33bddef (patch)
tree6d7045186772c2186d2541fb3625b16bbf7246af /scripts/context
parenta8d90ec17f9ba850721305edcf360407c3aae5b3 (diff)
downloadcontext-ddf4906882f4bea473964e5b0d209cc3a33bddef.tar.gz
beta 2012.06.11 00:21
Diffstat (limited to 'scripts/context')
-rw-r--r--scripts/context/lua/mtx-context.lua1
-rw-r--r--scripts/context/lua/mtx-epub.lua53
2 files changed, 49 insertions, 5 deletions
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 = [[
<dc:identifier id="%s" opf:scheme="UUID">urn:uuid:%s</dc:identifier>
<dc:creator>%s</dc:creator>
<dc:date>%s</dc:date>
+ <meta name="cover" content="%s" />
</metadata>
<manifest>
@@ -70,6 +71,7 @@ local package = [[
</manifest>
<spine toc="ncx">
+ <itemref idref="cover-xhtml" />
<itemref idref="%s" />
</spine>
@@ -108,6 +110,23 @@ local toc = [[
</ncx>
]]
+local coverxhtml = [[
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>cover.xhtml</title>
+ </head>
+ <body>
+ <div>
+ <img src="%s" alt="The cover image" style="max-width: 100%%;" />
+ </div>
+ </body>
+</html>
+]]
+
-- 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")