~flexibeast/epub-create

c44ddcb2f2d2d98318eadb98f65ff72035e104a6 — Alexis 1 year, 4 months ago 0b20abe
Add option to include cover page.
3 files changed, 104 insertions(+), 6 deletions(-)

M README.md
M epub-create
M epub-create.1
M README.md => README.md +7 -2
@@ 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`

M epub-create => epub-create +90 -3
@@ 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
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:epub="http://www.idpf.org/2007/ops"
      lang="${DOC_LANG}"
      xml:lang="${DOC_LANG}">
  <head>
    <title>Titlepage</title>
  </head>
  <body epub:type="frontmatter">
    <section id="titlepage"
             epub:type="titlepage">
      <h1 style="font-family:serif;font-size:150%;margin-top:3em;text-align:center;">
        ${TITLE}
      </h1>
      <h2 style="font-family:serif;font-size:120%;margin-top:3em;text-align:center;">
        ${AUTHORS}
      </h2>
    </section>
  </body>
</html>
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
        <dc:language>${DOC_LANG}</dc:language>
    </metadata>
    <manifest>
FIN
if [ -n "${COVER}" ]
then
    cat >> "${PACKAGE}" << FIN
        <item id="titlepage"
              href="titlepage.xhtml"
              media-type="application/xhtml+xml"/>
FIN
fi
cat >> "${PACKAGE}" << FIN
        <item id="nav"
              href="nav.xhtml"
              media-type="application/xhtml+xml"


@@ 150,6 226,10 @@ do
done
echo '    </manifest>' >> "${PACKAGE}"
echo '    <spine>' >> "${PACKAGE}"
if [ -n "${COVER}" ]
then
    echo "        <itemref idref=\"titlepage\"/>" >> "${PACKAGE}"
fi
for F in $(cat "${SPINE}")
do
    NAME=$(echo "${F}" | sed -e 's/\.[^.]*$//')


@@ 175,6 255,13 @@ cat >> "${NAV}" << FIN
      <h1>${TITLE}</h1>
      <ol>
FIN
if [ -n "${COVER}" ]
then
    create_titlepage
    echo '        <li>' >> "${NAV}"
    echo "          <a href=\"titlepage.xhtml\">Titlepage</a>" >> "${NAV}"
    echo '        </li>' >> "${NAV}"
fi
for F in $(cat "${SPINE}")
do
    NAME=$(echo "${F}" | sed -e 's/\.[^.]*$//')

M epub-create.1 => epub-create.1 +7 -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