Horrors2/mkepub

108 lines
2.5 KiB
Plaintext
Raw Permalink Normal View History

2009-11-18 20:45:24 -07:00
#! /bin/sh
kersplit () {
first=1
# Add an extra line to chop
parts=$( (cat horrors2.xhtml; echo) | sed -n '/class="part/=;$=')
for part in $parts; do
fn=$1; shift
cat head.xhtml > $fn
last=$(expr $part - 1)
sed -n "${first},${last}p" horrors2.xhtml >> $fn
cat foot.xhtml >> $fn
first=$part
done
}
xhtml="epub/book.xhtml epub/part1.xhtml epub/part2.xhtml epub/part3.xhtml epub/part4.xhtml epub/part5.xhtml epub/part6.xhtml epub/part7.xhtml"
kersplit $xhtml
2009-11-18 20:45:24 -07:00
rm -rf epub/art
if true; then
mkdir epub/art
for i in art/*.png; do
echo $i
pngtopnm $i | pnmscale -xysize 800 600 | pnmtopng > epub/$i
done
for i in art/*.jpg; do
echo $i
jpegtopnm $i | pnmscale -xysize 800 600 | pnmtojpeg > epub/$i
done
fi
2009-11-18 20:45:24 -07:00
cp style.css epub/
cd epub
echo -n application/epub+zip > mimetype
cat >MANIFEST <<EOF
mimetype
META-INF/container.xml
content.opf
EOF
cat > content.opf <<EOF
<?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>Horrors 2</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="BookId" opf:scheme="title">Horrors2</dc:identifier>
<dc:creator opf:file-as="Something Awful Forums" opf:role="aut">The Something Awful Forums</dc:creator>
</metadata>
<manifest>
EOF
rm spine
2009-11-18 20:45:24 -07:00
find . -type f | sed 's#./##' | while read fn; do
b=$(basename $fn)
id=thing$count
count=$(expr $count + 1)
case "$b" in
META-INF/*|MANIFEST|mimetype|content.opf|spine)
2009-11-18 20:45:24 -07:00
continue
;;
*.xhtml)
id=$(basename $b .xhtml)
2009-11-18 20:45:24 -07:00
type=application/xhtml+xml
echo $id >> spine
2009-11-18 20:45:24 -07:00
;;
*.css)
type=image/css
;;
book.ncx)
id=ncx
;;
*.png)
type=image/png
;;
*.jpg)
type=image/jpeg
;;
*.svg)
type=image/svg+xml
;;
*.otf)
type=application/octet-stream
;;
esac
echo "<item id=\"$id\" href=\"$fn\" media-type=\"$type\"/>" >> content.opf
echo $fn >> MANIFEST
done
cat >> content.opf <<EOF
</manifest>
<spine toc="ncx">
EOF
sort spine | while read id; do
# "book" sorts before "part*" :)
echo " <itemref idref=\"$id\" />" >> content.opf
done
rm spine
cat >> content.opf <<EOF
2009-11-18 20:45:24 -07:00
</spine>
</package>
EOF
xargs zip -Xr9D ../book.epub < MANIFEST