From 82748c30289377a5837d9d119912e691164cc0dc Mon Sep 17 00:00:00 2001 From: yetist Date: Tue, 30 Oct 2012 23:15:44 +0800 Subject: [PATCH] update genepu.sh --- genepub.sh | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/genepub.sh b/genepub.sh index 7ed4d466..01e071c0 100755 --- a/genepub.sh +++ b/genepub.sh @@ -1,21 +1,32 @@ -#!/bin/sh -if [ ! -f build-web-application-with-golang ];then - go build +#!/bin/bash +if ! which pandoc >/dev/null ;then + echo "请先安装pandoc,然后再次运行" + exit 0 fi - -if [ ! -d html ];then - mkdir html -fi -cd html -cp ../*.md . +[ -f build-web-application-with-golang ] && go build +[ -d html ] || mkdir html +pushd html >/dev/null; cp ../*.md . +sed -i 's!https://github.com/astaxie/build-web-application-with-golang/blob/master/!!g' README.md for i in *.md;do #重新格式化md文件 - sed -i '/^[#]\{1,\}/s!^\([#]\{1,\}\)\([^#]\{1,\}\)!\1 \2!' $i - sed -i '/^[#]\{1,\}/s! ! !' $i - #处理md文件中的image src属性 - sed -i '/!\[\](images/s#images\(.*\)?raw=true#../Images\1#' $i - + sed -i '/^[#]\{1,\}/s!^\([#]\{1,\}\)\([^#]\{1,\}\)!\1 \2!' $i #以#开头的行,在#后增加空格 + sed -i '/^[#]\{1,\}/s! ! !' $i #以#开头的行, 删除多余的空格 + #sed -i '/!\[\](images/s#images\(.*\)?raw=true#../Images\1#' $i + sed -i '/!\[\](images/s#images\(.*\)?raw=true#../images\1#' $i #处理md文件中的image src属性 + sed -i '/[#]\{2,\} links/,/[ ]\{0,\}Id\$.*/d' $i #删除页面链接 done ../build-web-application-with-golang >/dev/null -rm *.md -echo "文件已经就绪,请使用sigil导入html目录中的html文件和images目录中的图片文件,制作epub" +list="README.html `ls [1-9]*.html |sort -h` LICENSE.html" +cat > metadata.txt <Astaxie +一本开源的Go Web编程书籍 +zh-CN +Creative Commons +Go Web编程 +EOF + +pandoc --reference-links -S --toc -f html -t epub --epub-metadata=metadata.txt --epub-cover-image=../images/cover.png \ +-o ../build-web-application-with-golang.epub $list +popd >/dev/null +rm -rf html +echo "build-web-application-with-golang.epub 已经建立"