valid nav

This commit is contained in:
sejo 2022-01-10 12:53:03 -06:00
parent 71e38fc768
commit 1868608ae8
4 changed files with 29 additions and 5 deletions

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.

22
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
@ -135,6 +139,7 @@ ARGIND==2 && FNR==1{
function finishfile(){ function finishfile(){
# finish writing the previous content file # 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_list){ append("</ul>"); is_list = 0 }
if(is_pre){ append("</pre>"); is_pre = 0 } if(is_pre){ append("</pre>"); is_pre = 0 }
out = out " </main>\n </body>\n</html>" out = out " </main>\n </body>\n</html>"
@ -218,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
@ -228,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

@ -4,10 +4,11 @@
<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,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?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"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="en-US" xml:lang="en-US">
<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>