Files
build-web-application-with-…/ebook/build.sh
Shin Kojima 5d9b06f3d9 Add config as language file
This patch will change several behaviour while generating the ebook:

- `build.go` now accepts two environment variables: TMP, WORKDIR

    * TMP:

Temporary directory path.
The directory stores intermediate files like '*.html' or metadata.txt.

    * WORKDIR:

Script base directory.

- `config` as language file

config file will be `source`d to change its ebook metadata.

- `genepub.sh` is integrated to `build.sh` and `build.go`

See `FixHeader` and `RemoveFooterLink` functions.
2013-12-31 13:10:27 +09:00

47 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
bn="`basename $0`"
WORKDIR="$(cd $(dirname $0); pwd -P)"
#
# Default language: zh
# You can overwrite following variables in config file.
#
MSG_INSTALL_PANDOC_FIRST='请先安装pandoc然后再次运行'
MSG_SUCCESSFULLY_GENERATED='build-web-application-with-golang.epub 已经建立'
MSG_CREATOR='Astaxie'
MSG_DESCRIPTION='一本开源的Go Web编程书籍'
MSG_LANGUAGE='zh-CN'
MSG_TITLE='Go Web编程'
[ -e "$WORKDIR/config" ] && . "$WORKDIR/config"
TMP=`mktemp -d 2>/dev/null || mktemp -d -t "${bn}"` || exit 1
trap 'rm -rf "$TMP"' 0 1 2 3 15
cd "$TMP"
(
[ go list github.com/fairlyblank/md2min >/dev/null 2>&1 ] || export GOPATH="$PWD"
go get -u github.com/fairlyblank/md2min
WORKDIR="$WORKDIR" TMP="$TMP" go run "$WORKDIR/build.go"
)
if [ ! type -P pandoc >/dev/null 2>&1 ]; then
echo "$MSG_INSTALL_PANDOC_FIRST"
exit 0
fi
cat <<__METADATA__ > metadata.txt
<dc:creator>$MSG_CREATOR</dc:creator>
<dc:description>$MSG_DESCRIPTION</dc:description>
<dc:language>$MSG_LANGUAGE</dc:language>
<dc:rights>Creative Commons</dc:rights>
<dc:title>$MSG_TITLE</dc:title>
__METADATA__
pandoc --reference-links -S --toc -f html -t epub --epub-metadata=metadata.txt --epub-cover-image="$WORKDIR/../images/cover.png" -o "$WORKDIR/../build-web-application-with-golang.epub" `ls [0-9]*.html | sort`
echo "$MSG_SUCCESSFULLY_GENERATED"