日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

gitbook asciidoc 项目生成PDF 教程

發布時間:2023/12/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 gitbook asciidoc 项目生成PDF 教程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

環境

操作系統: win7
npm: 3.10.10

需求

今天在gitbook看elasticsearch權威指南時,發現與官網的有些不一樣,或者說官網上的中文文檔依然有些錯別字或者翻譯不對的地方。而gitbook上的源碼目前視乎還在更新,但是源碼看起來又特難受,于是乎我就折騰怎樣將其生成為PDF文件來看。

折騰一晚上總于又眉目啦

步驟

①安裝好gitbook環境
②將gitbook項目源碼;也就是GitHub項目clone下來。
③安裝ebook-convert。
④執行gitbook命令生成PDF

安裝gitbook環境

由于GitBook 是一個基于 Node.js 的命令行工具,可使用 Github/Git 和 Markdown 來制作精美的電子書。

所以我們要先安裝Node.js。

安裝Node.js

這里我就不介紹啦!

安裝gitbook

在安裝好Node.js之后在命令行中執行如下命令:

npm install gitbook-cli -g

驗證安裝是否成功:

C:\Users\yutao>npm -v 3.10.10

這里也簡單介紹下gitbook命令:

本地預覽

C:\Users\lenovo> gitbook serve ./圖書名稱

輸出一個靜態網站

C:\Users\lenovo> gitbook build 圖書目錄 輸出目錄

上面命令的路徑是項目路徑的上一層。也就是不要進入到項目文件夾中。

查看幫助

C:\Users\lenovo> gitbook help build [book] [output] build a book --format Format to build to (Default is website; Values are website, jso n, ebook) --log Minimum log level to display (Default is info; Values are debug , info, warn, error, disabled)pdf [book] [output] build a book to pdf --log Minimum log level to display (Default is info; Values are debug , info, warn, error, disabled)epub [book] [output] build a book to epub --log Minimum log level to display (Default is info; Values are debug , info, warn, error, disabled)mobi [book] [output] build a book to mobi --log Minimum log level to display (Default is info; Values are debug , info, warn, error, disabled)serve [book] Build then serve a gitbook from a directory --port Port for server to listen on (Default is 4000) --lrport Port for livereload server to listen on (Default is 35729) --watch Enable/disable file watcher (Default is true) --format Format to build to (Default is website; Values are website, jso n, ebook) --log Minimum log level to display (Default is info; Values are debug , info, warn, error, disabled)install [book] install plugins dependenciesinit [directory] create files and folders based on contents of SUMMARY.m d

安裝 ebook-convert

ebook-convert 下載地址

我下載的是Windows版。

安裝一下就可以,記得要啟動下,設置書庫路徑。

clone 項目

我clone的項目是:

git clone git@github.com:elasticsearch-cn/elasticsearch-definitive-guide.git

這里重點來了
首先,這個項目的文件格式是asciidoc的,網上大部分教程都是Markdown。
這就導致我查閱的資料很少,執行命令時總是報錯。

后來我才知道,這種類型格式的項目需要兩個文件:
① README.adoc 文件
② SUMMARY.adoc 文件

README.adoc 類似于這本書的介紹。
SUMMARY.adoc 就這本書的目錄結構。

這兩個文件都需要,書的介紹可以沒有,也就是README.adoc這個文件你可以什么都不寫空著就行。

但是SUMMARY.adoc是生成PDF時的關鍵。

編寫SUMMARY.adoc有兩種方式:

第一種
使用官方格式編寫目錄:

= Summary. link:chapter-1/README.adoc[Chapter 1] .. link:chapter-1/ARTICLE1.adoc[Article 1] .. link:chapter-1/ARTICLE2.adoc[Article 2] ... link:chapter-1/ARTICLE-1-2-1.adoc[Article 1.2.1] . link:chapter-2/README.adoc[Chapter 2] . link:chapter-3/README.adoc[Chapter 3] . link:chapter-4/README.adoc[Chapter 4] .. Unfinished article . Unfinished Chapter

對于我的項目而言就是:

= Summary. link:00_Getting_started.asciidoc[入門基礎] .. link:010_Intro/05_What_is_it.asciidoc[一切為了搜索] .. link:010_Intro/10_Installing_ES.asciidoc[安裝es] .. link:010_Intro/15_API.asciidoc[15_API.asciidoc] //我沒有寫全,只寫了一部分。。。

在執行:

E:\document\elasticsearch-definitive-guide>gitbook pdf ./ ./es.pdf

其中document是我自己創建的一個文件夾,我的項目結構:

執行完了后,項目中就多了個es.pdf 文件。


第二種 方法

利用 asciidocfx軟件中的PDF導出功能;
SUMMARY.adoc 文件要這么編寫:

include::010_Intro/05_What_is_it.asciidoc[]include::010_Intro/10_Installing_ES.asciidoc[]include::010_Intro/15_API.asciidoc[]include::010_Intro/20_Document.asciidoc[]include::010_Intro/25_Tutorial_Indexing.asciidoc[]include::010_Intro/30_Tutorial_Search.asciidoc[]include::010_Intro/35_Tutorial_Aggregations.asciidoc[]include::010_Intro/40_Tutorial_Conclusion.asciidoc[]include::010_Intro/45_Distributed.asciidoc[]include::010_Intro/50_Conclusion.asciidoc[]

再用asciidocfx這個軟件打開這個項目并打開定位到SUMMARY.adoc文件后,點擊右上方的PDF按鈕,等一會就會生成PDF文件。


參考地址:

https://tonydeng.github.io/gitbook-zh/gitbook-howtouse/output/pdfandebook.html

https://www.gitbook.com/book/yuzeshan/gitbook-studying/details

https://chrisniael.gitbooks.io/gitbook-documentation/content/format/asciidoc.html

https://yuzeshan.gitbooks.io/gitbook-studying/content/output/pdfandebook.html

https://www.gitbook.com/book/melody/asciidoc/details

https://www.gitbook.com/book/gitbookio/docs-toolchain/details

https://github.com/elasticsearch-cn/elasticsearch-definitive-guide

總結

以上是生活随笔為你收集整理的gitbook asciidoc 项目生成PDF 教程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。