streamlined templates
This commit is contained in:
parent
d6abdd4173
commit
8de31cbea3
5
Makefile
5
Makefile
|
@ -1,6 +1,9 @@
|
|||
clean:
|
||||
rm example-book.gpub
|
||||
gpub:
|
||||
rm -r out/
|
||||
example-gpub:
|
||||
cd example-gpub; zip -r ../example-book.gpub *; cd -
|
||||
epub:
|
||||
cd out; zip -r ../out.epub *; cd -
|
||||
example:
|
||||
awk -f g2e.awk example-gpub/
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
# g2e
|
||||
|
||||
an opinionated gempub to epub converter written in awk.
|
||||
|
||||
# usage
|
||||
|
||||
an example (uncompressed) gpub file is provided.
|
||||
|
||||
you can generate the corresponding epub file using:
|
||||
|
||||
```
|
||||
make example
|
||||
```
|
||||
|
||||
and then compress it with:
|
||||
|
||||
```
|
||||
make epub
|
||||
```
|
||||
|
||||
in order to convert another gpub, you can remix the following command, where `example-gpub/` would be the directory for your uncompressed gpub
|
||||
|
||||
```
|
||||
awk -f g2e.awk example-gpub/
|
||||
```
|
||||
|
||||
for the moment this only generates the epub metadata and table of contents files.
|
||||
|
||||
# TODO
|
||||
|
||||
* convert .gmi files to .xhtml
|
||||
* handle non-gmi files in the manifest
|
24
g2e.awk
24
g2e.awk
|
@ -1,6 +1,7 @@
|
|||
# awk -f g2e.awk example-gpub/
|
||||
BEGIN{
|
||||
gpubdir = ARGV[1]
|
||||
tdir = "templates/" # templates dir
|
||||
epubtdir = "template-epub/"
|
||||
epubodir = "out/"
|
||||
metadatafile = gpubdir "metadata.txt"
|
||||
|
@ -30,15 +31,21 @@ BEGIN{
|
|||
|
||||
# setup epub
|
||||
system( "mkdir -p " epubodir "OEBPS" )
|
||||
system( "cp -ru " epubtdir "META-INF " epubodir )
|
||||
system( "cp -u " epubtdir "mimetype " epubodir )
|
||||
system( "mkdir -p " epubodir "META-INF" )
|
||||
system( "cp -u " tdir "container.xml " epubodir "META-INF/" )
|
||||
system( "cp -u " tdir "mimetype " epubodir )
|
||||
|
||||
RS = "\f" # to get the whole file in one getline
|
||||
getline templates["content-header.opf"] < (epubtdir "OEBPS/content-header.opf")
|
||||
getline templates["toc-header.ncx"] < (epubtdir "OEBPS/toc-header.ncx")
|
||||
getline templates["toc-navmap.ncx"] < (epubtdir "OEBPS/toc-navmap.ncx")
|
||||
# read templates
|
||||
templatefiles ="find " tdir " -type f -not -name '.*'"
|
||||
while( (templatefiles | getline )>0 ){
|
||||
tpath = $0
|
||||
tkey = tpath
|
||||
sub(tdir, "", tkey)
|
||||
|
||||
RS = "\n" # return to normal
|
||||
RS = "\f" # to get the whole file in one getline
|
||||
getline templates[tkey] < tpath
|
||||
RS = "\n"
|
||||
}
|
||||
|
||||
content = write_template( "content-header.opf", meta )
|
||||
toc = write_template( "toc-header.ncx", meta )
|
||||
|
@ -75,8 +82,8 @@ ARGIND==1 && /^=>/{
|
|||
spinetoc = spinetoc " <itemref idref=\"" id "\" />\n"
|
||||
|
||||
toc = toc write_template( "toc-navmap.ncx", ch )
|
||||
|
||||
}
|
||||
|
||||
# when finished reading the index:
|
||||
ARGIND==2 && FNR==1{
|
||||
content = content " </manifest>\n\n" spinetoc " </spine>\n\n</package>"
|
||||
|
@ -90,6 +97,7 @@ ARGIND==2 && FNR==1{
|
|||
ARGIND>1{
|
||||
# print $0
|
||||
}
|
||||
|
||||
END{
|
||||
|
||||
}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<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" opf:scheme="ISBN">123456789X</dc:identifier>
|
||||
<dc:creator opf:role="aut">{author}</dc:creator>
|
||||
<dc:description>{description}</dc:description>
|
||||
<dc:date>{publishDate}</dc:date>
|
||||
</metadata>
|
||||
|
||||
<manifest>
|
||||
<item id="chapter1" href="chapter1.xhtml" media-type="application/xhtml+xml"/>
|
||||
<item id="appendix" href="appendix.xhtml" media-type="application/xhtml+xml"/>
|
||||
<item id="stylesheet" href="style.css" media-type="text/css"/>
|
||||
<item id="ch1-pic" href="ch1-pic.png" media-type="image/png"/>
|
||||
<item id="myfont" href="css/myfont.otf" media-type="application/x-font-opentype"/>
|
||||
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
|
||||
</manifest>
|
||||
|
||||
<spine toc="ncx">
|
||||
<itemref idref="chapter1" />
|
||||
<itemref idref="appendix" />
|
||||
</spine>
|
||||
|
||||
</package>
|
Loading…
Reference in New Issue