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.
This commit is contained in:
Shin Kojima
2013-12-31 06:42:13 +09:00
parent a0ca9d3556
commit dfe2104969
4 changed files with 130 additions and 68 deletions

View File

@@ -1,11 +1,46 @@
#!/bin/sh
rm -f *.html *~
bn="`basename $0`"
WORKDIR="$(cd $(dirname $0); pwd -P)"
export GOPATH=`pwd`
#
# 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"
#go get -u github.com/russross/blackfriday
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"
)
go run 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"