【原创】Gitbook使用

【经常使用命令】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;
相关文章
相关标签/搜索