45
genepub.sh
Normal file → Executable file
45
genepub.sh
Normal file → Executable file
@@ -1,21 +1,32 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
if [ ! -f build-web-application-with-golang ];then
|
if ! which pandoc >/dev/null ;then
|
||||||
go build
|
echo "请先安装pandoc,然后再次运行"
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
[ -f build-web-application-with-golang ] && go build
|
||||||
if [ ! -d html ];then
|
[ -d html ] || mkdir html
|
||||||
mkdir html
|
pushd html >/dev/null; cp ../*.md .
|
||||||
fi
|
sed -i 's!https://github.com/astaxie/build-web-application-with-golang/blob/master/!!g' README.md
|
||||||
cd html
|
|
||||||
cp ../*.md .
|
|
||||||
for i in *.md;do
|
for i in *.md;do
|
||||||
#<EFBFBD><EFBFBD><EFBFBD>¸<EFBFBD>ʽ<EFBFBD><EFBFBD>md<EFBFBD>ļ<EFBFBD>
|
#重新格式化md文件
|
||||||
sed -i '/^[#]\{1,\}/s!^\([#]\{1,\}\)\([^#]\{1,\}\)!\1 \2!' $i
|
sed -i '/^[#]\{1,\}/s!^\([#]\{1,\}\)\([^#]\{1,\}\)!\1 \2!' $i #以#开头的行,在#后增加空格
|
||||||
sed -i '/^[#]\{1,\}/s! ! !' $i
|
sed -i '/^[#]\{1,\}/s! ! !' $i #以#开头的行, 删除多余的空格
|
||||||
#<EFBFBD><EFBFBD><EFBFBD><EFBFBD>md<EFBFBD>ļ<EFBFBD><EFBFBD>е<EFBFBD>image src<72><63><EFBFBD><EFBFBD>
|
#sed -i '/!\[\](images/s#images\(.*\)?raw=true#../Images\1#' $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
|
done
|
||||||
../build-web-application-with-golang >/dev/null
|
../build-web-application-with-golang >/dev/null
|
||||||
rm *.md
|
list="README.html `ls [1-9]*.html |sort -h` LICENSE.html"
|
||||||
echo "<22>ļ<EFBFBD><C4BC>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>sigil<69><6C><EFBFBD><EFBFBD>htmlĿ¼<C4BF>е<EFBFBD>html<6D>ļ<EFBFBD><C4BC><EFBFBD>imagesĿ¼<C4BF>е<EFBFBD>ͼƬ<CDBC>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>epub"
|
cat > metadata.txt <<EOF
|
||||||
|
<dc:creator>Astaxie</dc:creator>
|
||||||
|
<dc:description>一本开源的Go Web编程书籍</dc:description>
|
||||||
|
<dc:language>zh-CN</dc:language>
|
||||||
|
<dc:rights>Creative Commons</dc:rights>
|
||||||
|
<dc:title>Go Web编程</dc:title>
|
||||||
|
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 已经建立"
|
||||||
|
|||||||
BIN
images/cover.png
Normal file
BIN
images/cover.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 123 KiB |
Reference in New Issue
Block a user