我使用GitBook主要是用于整理归档的,记录的内容相对比较系统一点,零散的内容就以博客的形式发布。构建博客使用的Hexo和GitBook是相对独立的两套程序,需要自己手动集成起来。将博客发布到github,其实就是将public目录更新到github上面,只要在执行hexo g之后,hexo d之前,将GitBook的内容生成到public目录就可以了。 在博客的根目录建立文件夹books,GitBook的内容就存放在这里,每个子目录存放一本电子书的内容,在books目录下执行如下的GitBook构建脚本,即可将电子书的内容集成到Hexo博客当中。

#!/bin/bash

source=../public/books
for dir in *;
do
#删除gitbook生成的内容
if [ -d $source/$dir ]; then
rm -r $source/$dir
fi
#重新生成gitbook的内容
if [ -d $dir ]; then
gitbook build $dir $source/$dir
fi
done

生成pdf文件,需要安装ebook-convert,Debian系统中,这个程序是包含在calibre包中。

sudo apt-get install calibre
gitbook pdf
Last Updated 2018-10-14 日 23:38.
Created by Emacs 25.1.1 (Org mode 9.1.14)