From 564b126de3c406f7dc430de4fc2863b0309442b0 Mon Sep 17 00:00:00 2001 From: Context Git Mirror Bot Date: Sat, 6 Sep 2014 13:15:04 +0200 Subject: 2014-09-06 12:52:00 --- scripts/context/lua/mtx-epub.lua | 182 +++++++++++++++++++++++++-------- scripts/context/lua/mtxrun.lua | 15 +-- scripts/context/stubs/mswin/mtxrun.lua | 15 +-- scripts/context/stubs/unix/mtxrun | 15 +-- scripts/context/stubs/win64/mtxrun.lua | 15 +-- 5 files changed, 176 insertions(+), 66 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/mtx-epub.lua b/scripts/context/lua/mtx-epub.lua index 9eb7a5c04..5c6f2cf10 100644 --- a/scripts/context/lua/mtx-epub.lua +++ b/scripts/context/lua/mtx-epub.lua @@ -18,7 +18,17 @@ if not modules then modules = { } end modules ['mtx-epub'] = { -- first we need a decent strategy to export them. More information will be -- available on the wiki. -local format, gsub = string.format, string.gsub +-- META-INF +-- container.xml +-- OEBPS +-- content.opf +-- toc.ncx +-- Images +-- Styles +-- Text +-- mimetype + +local format, gsub, find = string.format, string.gsub, string.find local concat = table.concat local replace = utilities.templates.replace @@ -71,18 +81,33 @@ local t_container = [[ ]] +-- urn:uuid: + +-- %uuid% + local t_package = [[ - + %title% %language% - urn:uuid:%uuid% + %uuid% %creator% %date% + + + %date% @@ -97,16 +122,18 @@ local t_package = [[ ]] -local t_item = [[ ]] +local t_item = [[ ]] +local t_nav = [[ ]] -local t_toc = [[ - +-- - +local t_toc = [[ + + @@ -133,23 +160,48 @@ local t_toc = [[ ]] -local t_coverxhtml = [[ +local t_navtoc = [[ - + + + navtoc + + + + + +]] + +-- +-- + +local t_coverxhtml = [[ + - cover.xhtml + cover page -
- The cover image +
+ %content%
]] +local t_coverimg = [[ + 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 @@ -165,6 +217,7 @@ end local mimetypes = { xhtml = "application/xhtml+xml", xml = "application/xhtml+xml", + html = "application/html", css = "text/css", svg = "image/svg+xml", png = "image/png", @@ -231,26 +284,32 @@ function scripts.epub.make() local specification = lfs.isfile(specfile) and dofile(specfile) or { } local name = specification.name or file.removesuffix(filename) - local identifier = specification.identifier or os.uuid(true) + local identifier = specification.identifier or "" local files = specification.files or { file.addsuffix(filename,"xhtml") } local images = specification.images or { } local root = specification.root or files[1] local language = specification.language or "en" - local creator = specification.author or "My Self" - local title = specification.title or "My Title" + local creator = specification.author or "context" + local title = specification.title or name local firstpage = specification.firstpage or "" local lastpage = specification.lastpage or "" -- identifier = gsub(identifier,"[^a-zA-z0-9]","") - if firstpage ~= "" then + if firstpage == "" then + -- firstpage = "firstpage.jpg" -- dummy + else images[firstpage] = firstpage end - if lastpage ~= "" then + if lastpage == "" then + -- lastpage = "lastpage.jpg" -- dummy + else images[lastpage] = lastpage end - identifier = "BookId" -- weird requirement + local uuid = format("urn:uuid:%s",os.uuid(true)) -- os.uuid() + + identifier = "bookid" -- for now local epubname = name local epubpath = file.replacesuffix(name,"tree") @@ -266,30 +325,51 @@ function scripts.epub.make() local used = { } - local function copyone(filename) + local function registerone(filename) local suffix = file.suffix(filename) local mime = mimetypes[suffix] if mime then local idmaker = idmakers[suffix] or idmakers.default - local target = file.join(epubpath,"OEBPS",filename) - file.copy(filename,target) - application.report("copying %s to %s",filename,target) used[#used+1] = replace(t_item, { - id = idmaker(filename), - filename = filename, - mime = mime, + id = idmaker(filename), + filename = filename, + mime = mime, } ) + return true end end - copyone("cover.xhtml") + local function copyone(filename,alternative) + if registerone(filename) then + local target = file.join(epubpath,"OEBPS",filename) + file.copy(alternative or filename,target) + application.report("copying %s to %s",alternative or filename,target) + end + end + + if lfs.isfile(epubcover) then + copyone(epubcover) + epubcover = false + else + registerone(epubcover) + end + copyone("toc.ncx") local function copythem(files) for i=1,#files do local filename = files[i] if type(filename) == "string" then +if file.suffix(filename) == "xhtml" then + local alternative = file.replacesuffix(filename,"html") + if lfs.isfile(alternative) then + copyone(filename,alternative) + else + copyone(filename) + end +else copyone(filename) +end end end end @@ -307,39 +387,55 @@ function scripts.epub.make() end end + used[#used+1] = replace(t_nav, { + id = "nav", + filename = "nav.xhtml", + properties = "nav", + mime = "application/xhtml+xml", + }) + + io.savedata(file.join(epubpath,"OEBPS","nav.xhtml"),replace(t_navtoc, { -- version 3.0 + root = root, + } ) ) + copythem(theimages) local idmaker = idmakers[file.suffix(root)] or idmakers.default - container = replace(t_container, { + io.savedata(file.join(epubpath,"mimetype"),mimetype) + + io.savedata(file.join(epubpath,"META-INF","container.xml"),replace(t_container, { -- version 2.0 rootfile = epubroot - } ) - package = replace(t_package, { + } ) ) + + io.savedata(file.join(epubpath,"OEBPS",epubroot),replace(t_package, { identifier = identifier, title = title, language = language, - uuid = os.uuid(), + uuid = uuid, creator = creator, date = os.date("!%Y-%m-%dT%H:%M:%SZ"), firstpage = idmaker(firstpage), manifest = concat(used,"\n"), rootfile = idmaker(root) - } ) - toc = replace(t_toc, { - identifier = identifier, + } ) ) + + -- t_toc is replaced by t_navtoc in >= 3 + + io.savedata(file.join(epubpath,"OEBPS",epubtoc), replace(t_toc, { + identifier = uuid, -- identifier, title = title, author = author, root = root, - } ) - coverxhtml = replace(t_coverxhtml, { - image = 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) + if epubcover then + + io.savedata(file.join(epubpath,"OEBPS",epubcover), replace(t_coverxhtml, { + content = firstpage ~= "" and replace(t_coverimg, { image = firstpage }) or "no cover page defined", + } ) ) + + end application.report("creating archive\n\n") @@ -383,3 +479,5 @@ elseif environment.argument("exporthelp") then else application.help() end + +-- java -jar d:\epubcheck\epubcheck-3.0.1.jar -v 3.0 -mode xhtml mkiv-publications.tree\mkiv-publications.epub diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index ffddc9de2..eae3060bf 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -7408,7 +7408,7 @@ do -- create closure to overcome 200 locals limit package.loaded["trac-log"] = package.loaded["trac-log"] or true --- original size: 25613, stripped down to: 16617 +-- original size: 25730, stripped down to: 16725 if not modules then modules={} end modules ['trac-log']={ version=1.001, @@ -7423,6 +7423,8 @@ local concat,insert,remove=table.concat,table.insert,table.remove local topattern=string.topattern local next,type,select=next,type,select local utfchar=utf.char +local datetime=os.date +local openfile=io.open local setmetatableindex=table.setmetatableindex local formatters=string.formatters local texgetcount=tex and tex.getcount @@ -7979,10 +7981,11 @@ function logs.application(t) end return t end -function logs.system(whereto,process,jobname,category,...) - local message=formatters["%s %s => %s => %s => %s\r"](os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)) +local f_syslog=formatters["%s %s => %s => %s => %s\r"] +function logs.system(whereto,process,jobname,category,fmt,arg,...) + local message=f_syslog(datetime("%d/%m/%y %H:%m:%S"),process,jobname,category,arg==nil and fmt or format(fmt,arg,...)) for i=1,10 do - local f=io.open(whereto,"a") + local f=openfile(whereto,"a") if f then f:write(message) f:close() @@ -17427,8 +17430,8 @@ end -- of closure -- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 720379 --- stripped bytes : 257438 +-- original bytes : 720496 +-- stripped bytes : 257447 -- end library merge diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index ffddc9de2..eae3060bf 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -7408,7 +7408,7 @@ do -- create closure to overcome 200 locals limit package.loaded["trac-log"] = package.loaded["trac-log"] or true --- original size: 25613, stripped down to: 16617 +-- original size: 25730, stripped down to: 16725 if not modules then modules={} end modules ['trac-log']={ version=1.001, @@ -7423,6 +7423,8 @@ local concat,insert,remove=table.concat,table.insert,table.remove local topattern=string.topattern local next,type,select=next,type,select local utfchar=utf.char +local datetime=os.date +local openfile=io.open local setmetatableindex=table.setmetatableindex local formatters=string.formatters local texgetcount=tex and tex.getcount @@ -7979,10 +7981,11 @@ function logs.application(t) end return t end -function logs.system(whereto,process,jobname,category,...) - local message=formatters["%s %s => %s => %s => %s\r"](os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)) +local f_syslog=formatters["%s %s => %s => %s => %s\r"] +function logs.system(whereto,process,jobname,category,fmt,arg,...) + local message=f_syslog(datetime("%d/%m/%y %H:%m:%S"),process,jobname,category,arg==nil and fmt or format(fmt,arg,...)) for i=1,10 do - local f=io.open(whereto,"a") + local f=openfile(whereto,"a") if f then f:write(message) f:close() @@ -17427,8 +17430,8 @@ end -- of closure -- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 720379 --- stripped bytes : 257438 +-- original bytes : 720496 +-- stripped bytes : 257447 -- end library merge diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index ffddc9de2..eae3060bf 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -7408,7 +7408,7 @@ do -- create closure to overcome 200 locals limit package.loaded["trac-log"] = package.loaded["trac-log"] or true --- original size: 25613, stripped down to: 16617 +-- original size: 25730, stripped down to: 16725 if not modules then modules={} end modules ['trac-log']={ version=1.001, @@ -7423,6 +7423,8 @@ local concat,insert,remove=table.concat,table.insert,table.remove local topattern=string.topattern local next,type,select=next,type,select local utfchar=utf.char +local datetime=os.date +local openfile=io.open local setmetatableindex=table.setmetatableindex local formatters=string.formatters local texgetcount=tex and tex.getcount @@ -7979,10 +7981,11 @@ function logs.application(t) end return t end -function logs.system(whereto,process,jobname,category,...) - local message=formatters["%s %s => %s => %s => %s\r"](os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)) +local f_syslog=formatters["%s %s => %s => %s => %s\r"] +function logs.system(whereto,process,jobname,category,fmt,arg,...) + local message=f_syslog(datetime("%d/%m/%y %H:%m:%S"),process,jobname,category,arg==nil and fmt or format(fmt,arg,...)) for i=1,10 do - local f=io.open(whereto,"a") + local f=openfile(whereto,"a") if f then f:write(message) f:close() @@ -17427,8 +17430,8 @@ end -- of closure -- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 720379 --- stripped bytes : 257438 +-- original bytes : 720496 +-- stripped bytes : 257447 -- end library merge diff --git a/scripts/context/stubs/win64/mtxrun.lua b/scripts/context/stubs/win64/mtxrun.lua index ffddc9de2..eae3060bf 100644 --- a/scripts/context/stubs/win64/mtxrun.lua +++ b/scripts/context/stubs/win64/mtxrun.lua @@ -7408,7 +7408,7 @@ do -- create closure to overcome 200 locals limit package.loaded["trac-log"] = package.loaded["trac-log"] or true --- original size: 25613, stripped down to: 16617 +-- original size: 25730, stripped down to: 16725 if not modules then modules={} end modules ['trac-log']={ version=1.001, @@ -7423,6 +7423,8 @@ local concat,insert,remove=table.concat,table.insert,table.remove local topattern=string.topattern local next,type,select=next,type,select local utfchar=utf.char +local datetime=os.date +local openfile=io.open local setmetatableindex=table.setmetatableindex local formatters=string.formatters local texgetcount=tex and tex.getcount @@ -7979,10 +7981,11 @@ function logs.application(t) end return t end -function logs.system(whereto,process,jobname,category,...) - local message=formatters["%s %s => %s => %s => %s\r"](os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)) +local f_syslog=formatters["%s %s => %s => %s => %s\r"] +function logs.system(whereto,process,jobname,category,fmt,arg,...) + local message=f_syslog(datetime("%d/%m/%y %H:%m:%S"),process,jobname,category,arg==nil and fmt or format(fmt,arg,...)) for i=1,10 do - local f=io.open(whereto,"a") + local f=openfile(whereto,"a") if f then f:write(message) f:close() @@ -17427,8 +17430,8 @@ end -- of closure -- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 720379 --- stripped bytes : 257438 +-- original bytes : 720496 +-- stripped bytes : 257447 -- end library merge -- cgit v1.2.3