Compare commits

..

No commits in common. "2e576a2d9b3c7601a1dae38b90673f156356de0e" and "7a4cf173f93ccdbed7970eb57ac283a70fcf9255" have entirely different histories.

6 changed files with 19 additions and 43 deletions

View File

@ -5,9 +5,7 @@ example-gpub:
cd example-gpub; zip -r ../example-book.gpub *; cd -
epub:
find . -name "out.epub" -exec rm {} \;
cd out; zip -X ../out.epub mimetype
cd out; zip -rg ../out.epub META-INF content.opf style.css toc.ncx book
cd out; zip -r ../out.epub *; cd -
example:
awk -f g2e.awk example-gpub/

View File

@ -39,7 +39,6 @@ example-gpub/
metadata.txt
book/
index.gmi
toc.gmi
cover.gmi
chapter1.gmi
chapter2.gmi
@ -53,10 +52,6 @@ example-gpub/
note that only `.gmi`, `.png`, `.jpg` and `.gif` files are handled.
## table of contents
there has to be a `toc.gmi` file that will be used as the `nav` element. this file has to have a single set of links pointed to internal `.gmi` files, not images.
## raw html
you can insert raw html using the corresponding `.gmo` syntax: the contents of a line that starts with `+` will be inserted as is.

28
g2e.awk
View File

@ -11,8 +11,6 @@ BEGIN{
epubodir = "out/"
metadatafile = gpubdir "metadata.txt"
"date -u +%FT%TZ" | getline meta["date"]
# read metadata file fields
while( getline < metadatafile ){
key = $1; sub(":","",key)
@ -92,9 +90,7 @@ ARGIND==1 && /^=>/{
ch["name"] = name
ch["num"]++
ch["dir"] = indexdirname
properties = ""
if( id~/^toc/ ) properties = "properties=\"nav\""
content = content " <item id=\"" id "\" href=\"" indexdirname id ".xhtml\" media-type=\"application/xhtml+xml\" " properties "/>\n"
content = content " <item id=\"" id "\" href=\"" indexdirname id ".xhtml\" media-type=\"application/xhtml+xml\"/>\n"
spinetoc = spinetoc " <itemref idref=\"" id "\" />\n"
toc = toc write_template( "toc-navpoint.ncx", ch )
next
@ -120,7 +116,7 @@ ARGIND==2 && FNR==1{
if(id~meta["cover"]){
properties = "properties=\"cover-image\""
}
content = content " <item id=\"" id "\" href=\"" dest "\" " properties " media-type=\"" mediatype "\"/>\n"
content = content " <item id=\"" id "\" href=\"" dest "\" media-type=\"" mediatype "\" " properties "/>\n"
}
$0 = line
@ -139,10 +135,7 @@ ARGIND==2 && FNR==1{
function finishfile(){
# finish writing the previous content file
if(name~/^toc$/){ append("</ol></nav>"); is_list = 0 }
if(is_list){ append("</ul>"); is_list = 0 }
if(is_pre){ append("</pre>"); is_pre = 0 }
out = out " </main>\n </body>\n</html>"
out = out "\t</main>\n </body>\n</html>"
print out > nameout
}
function append(line){
@ -223,19 +216,6 @@ sub(/^>[[:space:]]*/,""){
next
}
# toc links
name~/^toc$/ && sub(/^=>[[:space:]]*/,""){
link = $1
text = $2
for(i=3;i<=NF;i++) text = text " " $i
if(!is_list){ append("<nav epub:type=\"toc\"><ol>"); is_list = 1 }
sub(/gmi$/,"xhtml",link)
append("<li><a href=\"" link "\">" text "</a></li>")
next
}
# links?
sub(/^=>[[:space:]]*/,""){
link = $1
@ -246,7 +226,7 @@ sub(/^=>[[:space:]]*/,""){
append("<p><a href=\"" link "\">" text "</a></p>")
}
else if(link~/(gif|jpg|png)$/){
append("<picture><img src=\"" link "\" alt=\"" text "\" /></picture>")
append("<img src=\"" link "\" alt=\"" text "\" />")
}
else{
append("<p><a href=\"" link "\">" text "</a></p>")

View File

@ -1,14 +1,13 @@
<?xml version="1.0"?>
<package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:title>{title}</dc:title>
<dc:language>{language}</dc:language>
<dc:identifier id="BookId">{id}</dc:identifier>
<dc:creator id="creator">{author}</dc:creator>
<dc:identifier id="BookId" opf:scheme="ISBN">{id}</dc:identifier>
<dc:creator opf:role="aut">{author}</dc:creator>
<dc:description>{description}</dc:description>
<dc:date>{publishDate}</dc:date>
<meta property="dcterms:modified">{date}</meta>
<meta content="{cover}" name="cover"/>
</metadata>

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="en-US" xml:lang="en-US">
<?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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<title>{title}</title>
<link rel="stylesheet" href="../style.css" type="text/css" />
</head>
<body>
<header>
<h1 class="header">{title}</h1>
</header>
<main>
<header>
<h1>{title}</h1>
</header>
<main>

View File

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<ncx version="2005-1" xml:lang="en" xmlns="http://www.daisy.org/z3986/2005/ncx/">
<head>