故事背景:很多時候對外發布的產品需要一份html格式的文檔
首先要了解的是 word直接轉成html是不現實的,需要通過md文件來轉換。
我們本節課討論的Gitbook即是在MD基礎上進行操作的。
所以
任務一:安裝typora軟件,用于編輯md文件,簡單自學一下即可掌握
任務二:全局安裝gitbook
npm install -g gitbook-cli
任務三:打開當前目錄,執行
$ gitbook init
你會看到兩個文件,README.md 和 SUMMARY.md
將SUMMARY.md 文件拖入typora進行編輯
# 目錄* [前言](README.md)
* [第一章](one/README.md)* [1](one/one.md)* [2](one/two.md)* [3](one/three.md)
* [第二章](two/README.md)
* [第三章](three/README.md)
然后保存編輯,再次執行gitbook init,gitbook會根據這個summary文件內的結構創建相應的文件。
任務四:運行
$ gitbook serve
然后可以根據提示在本地查看運行效果
任務五:生成html
$ gitbook build
執行后會在_book目錄下生成我們需要的html文件,那么剩下的工作量其實就是維護md,這里建議使用git
拓展:
這里要補充兩點
第一: gitbook社區擁有很多插件,我們可以通過gitbook install命令來安裝,需要我們創建一個book.json文件,我自己使用的這份json文件可以用來參考
{"author": "yanhuinan","description": "devDoc","extension": null,"generator": "site","title": "二次開發文檔","language": "1c, abnf, accesslog, actionscript, ada, apache, applescript, arduino, armasm, asciidoc, aspectj, autohotkey, autoit, avrasm, awk, axapta, bash, basic, bnf, brainfuck, cal, capnproto, ceylon, clean, clojure, clojure-repl, cmake, coffeescript, coq, cos, cpp, crmsh, crystal, cs, csp, css, d, dart, delphi, diff, django, dns, dockerfile, dos, dsconfig, dts, dust, ebnf, elixir, elm, erb, erlang, erlang-repl, excel, fix, flix, fortran, fsharp, gams, gauss, gcode, gherkin, glsl, go, golo, gradle, groovy, haml, handlebars, haskell, haxe, hsp, htmlbars, http, hy, inform7, ini, irpf90, java, javascript, json, julia, kotlin, lasso, ldif, leaf, less, lisp, livecodeserver, livescript, llvm, lsl, lua, makefile, markdown, mathematica, matlab, maxima, mel, mercury, mipsasm, mizar, mojolicious, monkey, moonscript, n1ql, nginx, nimrod, nix, nsis, objectivec, ocaml, openscad, oxygene, parser3, perl, pf, php, pony, powershell, processing, profile, prolog, protobuf, puppet, purebasic, python, q, qml, r, rib, roboconf, rsl, ruby, ruleslanguage, rust, scala, scheme, scilab, scss, smali, smalltalk, sml, sqf, sql, stan, stata, step21, stylus, subunit, swift, taggerscript, tap, tcl, tex, thrift, tp, twig, typescript, vala, vbnet, vbscript, vbscript-html, verilog, vhdl, vim, x86asm, xl, xml, xquery, yaml, zephir","variables": {},"links": {"sharing": {"all": null,"facebook": null,"google": null,"twitter": null,"weibo": true,"wechat": true}},"output": null,"pdf": {"fontSize": 12,"footerTemplate": null,"headerTemplate": null,"margin": {"bottom": 36,"left": 62,"right": 62,"top": 36},"pageNumbers": false,"paperSize": "a4"},"plugins": ["-livereload","theme-comscore","-lunr","-search","search-plus@^0.0.11","simple-page-toc@^0.1.1","-highlight","prism@^2.0.3","prism-themes@^0.0.2","advanced-emoji@^0.2.1","anchors@^0.7.1","include-codeblock@^3.0.2","ace@^0.3.2","emphasize@^1.1.0","katex@^1.1.3","splitter@^0.0.8","mermaid-gb3@2.1.0","tbfed-pagefooter@^0.0.1","expandable-chapters-small@^0.1.7","donate@^1.0.2","favicon@^0.0.2","todo@^0.1.3","terminal@^0.3.2","alerts@^0.2.0","include-csv@^0.1.0","markdown-video","anchor-navigation-ex","embed-pdf","chart@^0.2.0"],"pluginsConfig": {"theme-default": {"showLevel": true},"prism": {"css": ["prismjs/themes/prism-okaidia.css"],"lang": {"flow": "javascript"}},"include-codeblock": {"template": "ace","unindent": true,"edit": true},"tbfed-pagefooter": {"copyright": "Copyright ? xdatainsight@yanhuinan","modify_label": "該文件修訂時間:","modify_format": "YYYY-MM-DD HH:mm:ss"},"donate": {"wechat": "./img/pay.jpg","title": "","button": "聯系作者","wechatText": "18380464736"},"simple-page-toc": {"maxDepth": 3,"skipFirstH1": true},"sectionx": {"tag": "b"},"favicon": {"shortcut": "favicon.ico","bookmark": "favicon.ico"},"terminal": {"copyButtons": true,"fade": false,"style": "flat"}}
}
第二:我們的gitbook還擁有生成pdf epub mobi格式的功能,但是經過試驗,效果不太好,暫時不推薦
來看一下最終效果