最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】Gitbook的本地预览和导出为html和PDF等其他格式

gitbook crifan 6797浏览 0评论

折腾:

【记录】试用Gitbook Editor去编辑Markdown的文章

后,去参考:

Mac环境安装Gitbook,并导出PDF教程 – 简书

安装 · GitBook 使用教程

去试试

gitbook serve

但是好像没有说在哪个路径下运行, 那就是可以全局运行了。

结果去试试:

➜  gitbook gitbook ls
GitBook Versions Installed:
    * 3.2.3
Run "gitbook update" to update to the latest version.
➜  gitbook gitbook serve
Live reload server started on port: 35729
Press CTRL+C to quit ...
FileNotFoundError: No "README" file (or is ignored)
➜  gitbook ll
➜  gitbook pwd
/Users/crifan/dev/dev_root/gitbook

(通过之前的Reveal in Finder而)找到Gitbook的book所在路径:

/Users/crifan/dev/dev_root/gitbook

对应着自己的刚新建的book

/Users/crifan/GitBook/Library/Import/httpzhi_shi_zheng_li

然后再去运行:

➜  httpzhi_shi_zheng_li git:(master) gitbook serve
Live reload server started on port: 35729
Press CTRL+C to quit ...
info: 7 plugins are installed
info: loading plugin "livereload"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 5 pages
info: found 4 asset files
info: >> generation finished with success in 0.7s !
Starting server ...
Serving book on http://localhost:4000

打开:

http://localhost:4000

看看效果:

然后右上角的导出,国内的只有weibo:

其他微信等都不支持。有机会去加上试试。

后记:

看到:

常用的插件都有哪些 · GitBook学习笔记

-》

https://plugins.gitbook.com/plugin/sharing-plus

支持了QQ等国内的分享。

貌似没有微信?

现在是左边的TOC目录,并没有显示出对应的编号:

1 xxx

2 xxx

之类的目录。

希望是:

TODO:

1.添加生成文章中的自动显示章节的数字编号

比如

1

1.1

1.1.1

之类的

2.添加其他,比如微信等的分享

【导出html】

去试试编译出html

貌似上面的gitbook serve,就已经先build了

-》所以本地可以看到对应的_book文件夹了

-》里面有所有的内容:

其中gitbook文件夹中有所有的字体,样式等内容:

去试试:

➜  httpzhi_shi_zheng_li git:(master) ✗ gitbook build
info: 7 plugins are installed
info: 6 explicitly listed
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 5 pages
info: found 3 asset files
info: >> generation finished with success in 1.5s !

看看上面已经看到过的输出的内容:

➜  httpzhi_shi_zheng_li git:(master) ✗ ll
total 48
-rw-r--r--   1 crifan  staff   110B 11 12 16:02 README.md
-rw-r--r--   1 crifan  staff   305B 11 12 17:46 SUMMARY.md
drwxr-xr-x  11 crifan  staff   374B 11 12 18:12 _book
drwxr-xr-x   4 crifan  staff   136B 11 12 17:00 assets
-rw-r--r--   1 crifan  staff   352B 11 12 17:39 ch1_http_intro.md
-rw-r--r--   1 crifan  staff   825B 11 12 17:03 httpde-dai-ma-fang-mian-de-ku.md
-rw-r--r--   1 crifan  staff   1.3K 11 12 17:00 httpde-dian-xing-gou-cheng.md
-rw-r--r--   1 crifan  staff   1.0K 11 12 17:22 httpde-request-zhong-de-can-shu-bian-ma-parameter-encoding.md
➜  httpzhi_shi_zheng_li git:(master) ✗ ll _book
total 200
drwxr-xr-x   4 crifan  staff   136B 11 12 18:12 assets
-rw-r--r--   1 crifan  staff   8.7K 11 12 18:12 ch1_http_intro.html
drwxr-xr-x  12 crifan  staff   408B 11 12 18:12 gitbook
-rw-r--r--   1 crifan  staff   9.9K 11 12 18:12 httpde-dai-ma-fang-mian-de-ku.html
-rw-r--r--   1 crifan  staff    10K 11 12 18:12 httpde-dian-xing-gou-cheng.html
-rw-r--r--   1 crifan  staff    10K 11 12 18:12 httpde-request-zhong-de-can-shu-bian-ma-parameter-encoding.html
-rw-r--r--   1 crifan  staff   7.9K 11 12 18:12 index.html
-rw-r--r--   1 crifan  staff    42K 11 12 18:12 search_index.json
➜  httpzhi_shi_zheng_li git:(master) ✗ ll _book/gitbook
total 536
drwxr-xr-x  3 crifan  staff   102B 11 12 18:12 fonts
drwxr-xr-x  4 crifan  staff   136B 11 12 18:12 gitbook-plugin-fontsettings
drwxr-xr-x  4 crifan  staff   136B 11 12 18:12 gitbook-plugin-highlight
drwxr-xr-x  4 crifan  staff   136B 11 12 18:12 gitbook-plugin-lunr
drwxr-xr-x  6 crifan  staff   204B 11 12 18:12 gitbook-plugin-search
drwxr-xr-x  3 crifan  staff   102B 11 12 18:12 gitbook-plugin-sharing
-rw-r--r--  1 crifan  staff   103K 11 12 18:12 gitbook.js
drwxr-xr-x  4 crifan  staff   136B 11 12 18:12 images
-rw-r--r--  1 crifan  staff    51K 11 12 18:12 style.css
-rw-r--r--  1 crifan  staff   111K 11 12 18:12 theme.js

如此,把整个_book文件夹上传到对应目录,即可显示了。

然后用ftp传到自己网站上,打开对应的地址:

https://www.crifan.com/files/doc/gitbook/http_summary/index.html

效果是:

总体还行。

【导出为PDF】

继续参考:

Mac环境安装Gitbook,并导出PDF教程 – 简书

【记录】下载安装使用电子书阅读器转换器Calibre

然后直接把app拖动到terminal可以得到其路径

➜  ~ /Applications/calibre.app
➜  calibre.app

然后去:

➜  calibre.app sudo ln -s /Applications/calibre.app/Contents/MacOS/ebook-convert /usr/local/bin/ebook-convert
Password:
➜  calibre.app ll /usr/local/bin/ebook-convert
lrwxr-xr-x  1 root  admin    54B 12  1 09:44 /usr/local/bin/ebook-convert -> /Applications/calibre.app/Contents/MacOS/ebook-convert
➜  calibre.app where ebook-convert
/usr/local/bin/ebook-convert
➜  calibre.app which ebook-convert
/usr/local/bin/ebook-convert

然后继续去转换为pdf等其他格式

➜  htttp_summary git:(master) gitbook pdf . ./output/http_summary.pdf
info: 9 plugins are installed
info: 5 explicitly listed
info: loading plugin "highlight"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 19 pages
info: found 26 asset files
info: >> generation finished with success in 14.0s !
info: >> 1 file(s) generated

导出的pdf:

PDF的效果:

效果还可以的。

再去转换其他格式:

➜  htttp_summary git:(master) gitbook epub ./ ./output/http_summary.epub
info: 9 plugins are installed
info: 5 explicitly listed
info: loading plugin "highlight"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 19 pages
info: found 26 asset files
info: >> generation finished with success in 8.2s !
info: >> 1 file(s) generated
➜  htttp_summary git:(master) gitbook mobi ./ ./output/http_summary.mobi
info: 9 plugins are installed
info: 5 explicitly listed
info: loading plugin "highlight"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 19 pages
info: found 26 asset files
info: >> generation finished with success in 12.9s !
info: >> 1 file(s) generated

然后用之前安装的Calibre打开看看epub和mobi的效果:

更多内容详见:

【记录】下载安装使用电子书阅读器转换器Calibre

另外,顺带去看看,gitbook去build,除了默认的website还支持其他的格式

json

➜  htttp_summary git:(master) gitbook build --format=json . ./output
info: 9 plugins are installed
info: 5 explicitly listed
info: loading plugin "highlight"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 19 pages
info: found 26 asset files
info: >> generation finished with success in 0.8s !

的效果:

输出ebook:

➜  htttp_summary git:(master) gitbook build --format=ebook . ./output
info: 9 plugins are installed
info: 5 explicitly listed
info: loading plugin "highlight"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 19 pages
info: found 26 asset files
info: >> generation finished with success in 1.2s !

效果

【总结】

Gitbook中,导出pdf等其他格式的步骤是:

1.安装Calibre

https://calibre-ebook.com/download下载到Mac的calibre-3.12.0.dmg

打开,拖到 应用程序中,即可看到:calibre.app

2.把calibre.app加入到PATH

sudo ln -s /Applications/calibre.app/Contents/MacOS/ebook-convert /usr/local/bin/ebook-convert

然后可以用:

which ebook-convert

确认的确terminal中可以找到ebook-convert

3.去转换不同格式:

创建输出目录:

mkdir output/pdf output/epub output/mobi output/website

导出不同格式,website/pdf/epub/mobi:

<code>gitbook build . ./output/website
gitbook pdf . ./output/pdf/http_summary.pdf
gitbook epub . ./output/epub/http_summary.epub
gitbook mobi . ./output/mobi/http_summary.mobi
</code>

输出的文件:

更多的文件结构方面详见:

【记录】gitbook优化book的文件组织结构

转载请注明:在路上 » 【记录】Gitbook的本地预览和导出为html和PDF等其他格式

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.177 seconds, using 22.01MB memory