diff --git a/README.md b/README.md index 30967ce..bd3a9e1 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ example-gpub/ metadata.txt book/ index.gmi + toc.gmi cover.gmi chapter1.gmi chapter2.gmi @@ -52,6 +53,10 @@ 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. diff --git a/g2e.awk b/g2e.awk index 7f02cee..f3092d8 100644 --- a/g2e.awk +++ b/g2e.awk @@ -11,6 +11,8 @@ 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) @@ -90,7 +92,9 @@ ARGIND==1 && /^=>/{ ch["name"] = name ch["num"]++ ch["dir"] = indexdirname - content = content " \n" + properties = "" + if( id~/^toc/ ) properties = "properties=\"nav\"" + content = content " \n" spinetoc = spinetoc " \n" toc = toc write_template( "toc-navpoint.ncx", ch ) next @@ -135,6 +139,7 @@ ARGIND==2 && FNR==1{ function finishfile(){ # finish writing the previous content file + if(name~/^toc$/){ append(""); is_list = 0 } if(is_list){ append(""); is_list = 0 } if(is_pre){ append(""); is_pre = 0 } out = out " \n \n" @@ -218,6 +223,19 @@ 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("