【經常使用命令】css
1.gitbook installhtml
安裝依賴模塊git
2.gitbook buildweb
編譯,結果輸出在_book文件夾下segmentfault
3.gitbook serveui
本機預覽,默認端口爲4000spa
【注意事項】debug
1.圖片文件名不能帶中文code
後果:圖片不能顯示。orm
2.根目錄只能有兩個MD文件
後果:若是根目錄存在除了README.md和SUMMARY.md以外的md文件,點擊README.md對應的菜單會沒法正常跳轉。
3.建議圖片、視頻上下文各保留一行空行
後果:圖片或視頻與文字之間沒有換行,格式錯亂。
4.SUMMARY.md的同一菜單最好放在相同目錄下(拖動菜單位置可能會致使目錄錯亂),刪除無用的md文件(菜單建立後刪除不會自動刪除文件)
後果:方便管理,減小垃圾文件,減小出現不可預料錯誤的可能性。
【其餘】
1.修改首頁連接
默認README.md的連接爲「./」,但有的時候不能指向默認的index.html文件。
修改文件:C:\Users\{用戶名}\.gitbook\versions\{版本號}\lib\output\helper\fileToURL.js
修改成下面內容(註釋掉三行)
function fileToURL(output, filePath) { var options = output.getOptions(); var directoryIndex = options.get('directoryIndex'); filePath = fileToOutput(output, filePath); /*if (directoryIndex && path.basename(filePath) == 'index.html') { filePath = path.dirname(filePath) + '/'; }*/ return LocationUtils.normalize(filePath); }
修改後,再使用gitbook build後的首頁連接就是「./index.html」
2.build時出錯,「gitbook Error: ENOENT: no such file or directory, stat........xxx.css」
參考連接:https://segmentfault.com/q/1010000009569245
修改文件:C:\Users\{用戶名}\.gitbook\versions\{版本號}\lib\output\website\copyPluginAssets.js
修改112行(最下面),以下:
...... logger.debug.ln('copy resources from plugin', assetsFolder); return fs.copyDir( assetsFolder, assetOutputFolder, { deleteFirst: false, overwrite: true/*, confirm: true*/ } ); } module.exports = copyPluginAssets;