第二次用了,记录下来,下次就不用在查资料了。
gitbook 网站生成的 pdf 中文字体非常难看,字体大小不一。
解决办法是手工指定中文字体,指定 pdf 文字大小。
book.json 例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | { "gitbook": "2.x.x", "title": "Go语言圣经", "description": "<The Go Programming Language>中文版", "language": "zh", "structure": { "readme": "preface.md" }, "pluginsConfig": { "fontSettings": { "theme": "white", "family": "msyh", "size": 2 }, "plugins": [ "yahei", "katex", "-search" ] }, "pdf": { "pageNumbers": true, "fontSize": 18, "paperSize": "a4", "margin": { "right": 30, "left": 30, "top": 30, "bottom": 50 } } } |
例子使用的 微软雅黑 字体,默认linux下没有这个字体,需要手工将字体拷贝到 /usr/share/fonts/truetype 目录。
可以通过 travis 自动生成 pdf 文件,.travis.yml 例子是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | language: node_js node_js: - "stable" script: - echo pass before_deploy: - sudo apt-get update -qq # install Chinese fonts - sudo apt-get install -y fonts-arphic-gbsn00lp golang # Install Gitbook - npm install gitbook-cli -g - npm install svgexport -g - npm install gitbook-plugin-yahei # Clone the repository - sudo -v && wget --no-check-certificate -nv -O- https://raw.githubusercontent.com/kovidgoyal/calibre/master/setup/linux-installer.py | sudo python -c "import sys; main=lambda:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main()" - sudo cp tools/*.ttc /usr/share/fonts/truetype - go run zh2tw.go . .md$ tw2zh - gitbook install - gitbook build ./ --format=json - gitbook build ./ - gitbook pdf ./ ./gopl-ch.pdf - gitbook epub ./ ./gopl-ch.epub - gitbook mobi ./ ./gopl-ch.mobi deploy: provider: releases api_key: $CI_USER_TOKEN skip_cleanup: true file: - gopl-ch.pdf - gopl-ch.epub - gopl-ch.mobi on: tags: true all_branches: true |
这个例子会在每次 git tag 时自动生成 pdf 文件,并发布到 github 。需要将 github token 设在到 CI_USER_TOKEN 环境变量。
厉害了,找了很久,属你这篇博客最吊
厉害了,找了很久,属你这篇博客最吊