Compare commits

...

6 Commits

Author SHA1 Message Date
sejo 2e576a2d9b valid toc.ncx 2022-01-10 13:06:11 -06:00
sejo 1868608ae8 valid nav 2022-01-10 12:53:03 -06:00
sejo 71e38fc768 correct version, header and main are back 2022-01-10 12:20:44 -06:00
sejo 25a7a537bd zip in required order 2022-01-10 11:44:47 -06:00
sejo 8d456b6a7c remove <main> and <header> 2022-01-10 11:44:21 -06:00
sejo 6f96dae334 close <ul> and <pre> at end of file 2022-01-10 11:28:41 -06:00
6 changed files with 43 additions and 19 deletions

View File

@ -5,7 +5,9 @@ example-gpub:
cd example-gpub; zip -r ../example-book.gpub *; cd - cd example-gpub; zip -r ../example-book.gpub *; cd -
epub: epub:
cd out; zip -r ../out.epub *; cd - 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
example: example:
awk -f g2e.awk example-gpub/ awk -f g2e.awk example-gpub/

View File

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

View File

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

View File

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

View File

@ -1,7 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?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/"> <ncx version="2005-1" xml:lang="en" xmlns="http://www.daisy.org/z3986/2005/ncx/">
<head> <head>