From c44ddcb2f2d2d98318eadb98f65ff72035e104a6 Mon Sep 17 00:00:00 2001 From: Alexis Date: Sun, 30 Apr 2023 14:18:31 +1000 Subject: [PATCH] Add option to include cover page. --- README.md | 9 +++-- epub-create | 93 +++++++++++++++++++++++++++++++++++++++++++++++++-- epub-create.1 | 8 ++++- 3 files changed, 104 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9af53e7..c1bb821 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,7 @@ EPUB-CREATE(1) - General Commands Manual # SYNOPSIS -**epub-create** -*dir* +**epub-create** \[**-o** cover] *dir* # DESCRIPTION @@ -62,6 +61,12 @@ date(1p) and zip(1). +# OPTIONS + +**-o** cover + +> Generate a cover page with document title and author(s). + # ENVIRONMENT `EDITOR` diff --git a/epub-create b/epub-create index cd11b2a..b3d9a46 100755 --- a/epub-create +++ b/epub-create @@ -17,14 +17,52 @@ then exit 1 fi -USAGE='Usage: epub-create [dir]' -if [ ! "${#}" -eq 1 ] +USAGE='Usage: epub-create [-o cover] dir' + +while getopts o: OPT +do + case "${OPT}" in + o) + if [ -z "${OPTARG}" ] + then + echo "-o option requires argument of 'cover'." + exit 1 + else + O_ARGS="${OPTARG}" + fi + ;; + *) + echo "Unrecognised option." + echo "${USAGE}" + exit 1 + ;; + esac +done +shift $(("${OPTIND}" - 1)) + +if [ -z "${1}" ] then echo "${USAGE}" exit 1 +else + DIR="${1}" +fi + +if [ -n "${O_ARGS}" ] +then + if [ "${O_ARGS}" = 'cover' ] + then + COVER=true + else + echo "Unrecognised argument to -o, exiting." + exit 1 + fi +else + COVER= fi create_epub () { + WORK_DIR="${1}" OUT_FILE="${2}" ( @@ -34,9 +72,36 @@ create_epub () { zip -X "${OUT_FILE}" mimetype > /dev/null; zip -urX "${OUT_FILE}" ./* > /dev/null; ) + +} + +create_titlepage () { + + cat >> "${TITLEPAGE}" << FIN + + + + Titlepage + + +
+

+ ${TITLE} +

+

+ ${AUTHORS} +

+
+ + +FIN + } -DIR="${1}" printf %s 'Title? ' read -r TITLE @@ -58,6 +123,7 @@ EPUB="${TMP_DIR}/$DIR" CONTAINER="${EPUB}/META-INF/container.xml" PACKAGE="${EPUB}/EPUB/opf.opf" NAV="${EPUB}/EPUB/nav.xhtml" +TITLEPAGE="${EPUB}/EPUB/titlepage.xhtml" mkdir "${EPUB}" mkdir "${EPUB}/META-INF" @@ -136,6 +202,16 @@ cat >> "${PACKAGE}" << FIN ${DOC_LANG} +FIN +if [ -n "${COVER}" ] +then + cat >> "${PACKAGE}" << FIN + +FIN +fi +cat >> "${PACKAGE}" << FIN ' >> "${PACKAGE}" echo ' ' >> "${PACKAGE}" +if [ -n "${COVER}" ] +then + echo " " >> "${PACKAGE}" +fi for F in $(cat "${SPINE}") do NAME=$(echo "${F}" | sed -e 's/\.[^.]*$//') @@ -175,6 +255,13 @@ cat >> "${NAV}" << FIN

${TITLE}

    FIN +if [ -n "${COVER}" ] +then + create_titlepage + echo '
  1. ' >> "${NAV}" + echo " Titlepage" >> "${NAV}" + echo '
  2. ' >> "${NAV}" +fi for F in $(cat "${SPINE}") do NAME=$(echo "${F}" | sed -e 's/\.[^.]*$//') diff --git a/epub-create.1 b/epub-create.1 index a752b8a..62af9c4 100644 --- a/epub-create.1 +++ b/epub-create.1 @@ -1,4 +1,4 @@ -.Dd April 29, 2023 +.Dd April 30, 2023 .Dt EPUB-CREATE 1 .Os .Sh NAME @@ -6,6 +6,7 @@ .Nd simple shell script for creating EPUB documents .Sh SYNOPSIS .Nm +.Op Fl o No cover .Ar dir .Sh DESCRIPTION .Nm @@ -58,6 +59,11 @@ requiring only the presence of .Xr date 1p and .Xr zip 1 . +.Sh OPTIONS +.Bl -tag -width x +.It Fl o No cover +Generate a cover page with document title and author(s). +.El .Sh ENVIRONMENT .Bl -tag -width x .It Ev EDITOR -- 2.45.2