diff --git a/Makefile b/Makefile
index 03e1a52..ca2e19e 100644
--- a/Makefile
+++ b/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/
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..84cf3df
--- /dev/null
+++ b/README.md
@@ -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
diff --git a/g2e.awk b/g2e.awk
index ad127b9..3227d89 100644
--- a/g2e.awk
+++ b/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 " \n"
toc = toc write_template( "toc-navmap.ncx", ch )
-
}
+
# when finished reading the index:
ARGIND==2 && FNR==1{
content = content " \n\n" spinetoc " \n\n"
@@ -90,6 +97,7 @@ ARGIND==2 && FNR==1{
ARGIND>1{
# print $0
}
+
END{
}
diff --git a/template-epub/OEBPS/content.opf b/template-epub/OEBPS/content.opf
deleted file mode 100644
index 2d9823d..0000000
--- a/template-epub/OEBPS/content.opf
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
- {title}
- {language}
- 123456789X
- {author}
- {description}
- {publishDate}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/template-epub/META-INF/container.xml b/templates/container.xml
similarity index 100%
rename from template-epub/META-INF/container.xml
rename to templates/container.xml
diff --git a/template-epub/OEBPS/content-header.opf b/templates/content-header.opf
similarity index 100%
rename from template-epub/OEBPS/content-header.opf
rename to templates/content-header.opf
diff --git a/template-epub/mimetype b/templates/mimetype
similarity index 100%
rename from template-epub/mimetype
rename to templates/mimetype
diff --git a/template-epub/OEBPS/toc-header.ncx b/templates/toc-header.ncx
similarity index 100%
rename from template-epub/OEBPS/toc-header.ncx
rename to templates/toc-header.ncx
diff --git a/template-epub/OEBPS/toc-navmap.ncx b/templates/toc-navmap.ncx
similarity index 100%
rename from template-epub/OEBPS/toc-navmap.ncx
rename to templates/toc-navmap.ncx