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

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

gitbook crifan 2836浏览 0评论

折腾:

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

期间,发现默认的配置,在功能复杂点的时候,文件目录结构有点乱:

  • 直接输出_books和一堆md同层,结构不清晰

  • gitbook的build和serve没有指定对应目录

参考:

<code>➜  htttp_summary git:(master) gitbook help
    build [book] [output]       build a book
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
        --format                Format to build to (Default is website; Values are website, json, ebook)
        --[no-]timing           Print timing debug information (Default is false)

    serve [book] [output]       serve the book as a website for testing
        --port                  Port for server to listen on (Default is 4000)
        --lrport                Port for livereload server to listen on (Default is 35729)
        --[no-]watch            Enable file watcher and live reloading (Default is true)
        --[no-]live             Enable live reloading (Default is true)
        --[no-]open             Enable opening book in browser (Default is false)
        --browser               Specify browser for opening book (Default is )
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
        --format                Format to build to (Default is website; Values are website, json, ebook)

    install [book]              install all plugins dependencies
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

    parse [book]                parse and print debug information about a book
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

    init [book]                 setup and create files for chapters
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

    pdf [book] [output]         build a book into an ebook file
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

    epub [book] [output]        build a book into an ebook file
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

    mobi [book] [output]        build a book into an ebook file
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

</code>

所以经过一番折腾,变成:

1.把所有的md相关源码都放到src下

2.把所有的数据,包括html,和以后的pdf等,都输出到output

其中需要注意的是:

之前对于gitbook的用法不熟悉,写成:

gitbook build ./src ./output

gitbook serve ./src ./output

导致book.json的配置无效:

  • search还存在

  • 目录的索引丢失

【总结】

最后改为正确的:

gitbook build . ./output

gitbook serve . ./output

意思是:

从.当前目录去找book.json(book.json中配置了md源码的所在位置了)

然后输出到output中

相关的命令:

➜  htttp_summary git:(master) pwd

/Users/crifan/GitBook/Library/Import/htttp_summary

➜  htttp_summary git:(master) ll

total 8

-rw-r–r–   1 crifan  staff   467B 12  1 10:17 book.json

drwxr-xr-x  19 crifan  staff   608B 11 29 14:11 node_modules

drwxr-xr-x  10 crifan  staff   320B 12  1 10:23 output

drwxr-xr-x  11 crifan  staff   352B 12  1 10:20 src

➜  htttp_summary git:(master) ll src

total 16

-rw-r–r–   1 crifan  staff   282B 12  1 10:01 README.md

-rw-r–r–   1 crifan  staff   1.1K 12  1 10:01 SUMMARY.md

drwxr-xr-x  10 crifan  staff   320B 12  1 10:19 _book

drwxr-xr-x   5 crifan  staff   160B 11 29 14:43 appendix

drwxr-xr-x   4 crifan  staff   128B 11 20 19:55 assets

drwxr-xr-x   8 crifan  staff   256B 11 25 22:47 http_detail

drwxr-xr-x   7 crifan  staff   224B 11 25 22:44 http_intro

drwxr-xr-x   6 crifan  staff   192B 12  1 10:02 http_related

➜  htttp_summary git:(master) cat book.json

{

  “title”: “HTTP知识总结”,

  “description”: “总结HTTP方面的技术供参考和学习”,

  “author”: “Crifan Li <[email protected]>”,

  “language”: “zh-hans”,

  “gitbook”: “3.2.3”,

  “root”: “./src”,

  “links”: {

    “sidebar”: {

      “主页”: “https://www.crifan.com”;,

      “Github源码”: “https://github.com/crifan/http_summary”;

    }

  },

  “plugins”: [

    “-search”

  ],

  “pluginsConfig”: {

    “theme-default”: {

        “showLevel”: true

    }

  }

}%                                                                                                                                     ➜  htttp_summary git:(master) gitbook build . ./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.9s !

➜  htttp_summary git:(master) gitbook serve . ./output

Live reload server started on port: 35729

Press CTRL+C to quit …

info: 9 plugins are installed

info: 6 explicitly listed

info: loading plugin “livereload”… OK

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.8s !

Starting server …

Serving book on http://localhost:4000

和效果如下:

转载请注明:在路上 » 【记录】gitbook优化book的文件组织结构

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.180 seconds, using 22.13MB memory