简体   繁体   English

无法在gitbook主题中添加自定义模板文件

[英]not able to add custom template files in gitbook themes

I am trying to create a custom gitbook theme and in that I also want to change the layout so that the book I create using the theme have the layout that I want. 我试图创建一个自定义gitbook主题,并且我还想更改布局,以使使用主题创建的书具有所需的布局。 I copied the default templates dir in my assests dir of the custom theme and then modified the layout.html and header.html files as I wanted. 我将默认模板目录复制到自定义主题的assets目录中,然后根据需要修改layout.html和header.html文件。 Then to include the modified template files, I added the following attribute to the index.js file 然后,为了包含修改后的模板文件,我将以下属性添加到index.js文件中

module.exports = {
    book: {
        assets: "./assests",
        templates: {
            "layout":"templates/layout.html",
            "header":"templates/includes/book/header.html",
        },
......
......

However with this configuration, the generated book is not picking the template file changes. 但是,使用此配置,生成的书不会选择模板文件的更改。 However I do see the css/js changes that I had done. 但是我确实看到了我所做的css / js更改。

For the record, layout and header template files do exist if you're going the "unadvised" (emphasizing the unadvised nature of this) route of: 为了记录,如果您要进行以下操作的“未建议的”(强调此建议的不建议的性质)路径,则布局和标题模板文件确实存在:

  1. Add "theme": "./customtheme" to your book.json file. 在您的book.json文件中添加“ theme”:“ ./customtheme”。
  2. Create your customtheme folder in the root with the files from the Gitbook repo 根从文件创建customtheme文件夹Gitbook回购
  3. Edit from there 从那里编辑

This is so far the only way I've found edit your favicon, sidebar, header, and layout files. 到目前为止,这是我发现编辑网站图标,边栏,标题和布局文件的唯一方法。 It's not recommended because you're no longer using the files in the repo, so updates could break it, but some things either aren't easy or possible to make changes without doing something messy and hacky like this. 不建议这样做,因为您不再使用存储库中的文件,因此更新可能会破坏该文件,但是有些事情要么不容易,要么就可能进行更改,而又不会像这样杂乱无章。 Hopefully simple things like updating a favicon, header, or sidebar could be made to be easier in the future. 希望将来可以简化一些简单的事情,例如更新图标,标题或边栏。 I've only found this solution after many, many google searches and plugin comparisons, so maybe some one has a better solution that I haven't found yet. 经过许多次Google搜索和插件比较后,我才发现此解决方案,因此也许有人找到了一个更好的解决方案,但我还没有找到。

Templates "layout" and "header" don't exist. 模板“布局”和“标题”不存在。 You can only change: 您只能更改:

  • site : template for the website site网站模板
  • glossary : template for the glossary 词汇表词汇表的模板
  • langs : template for the choice of languages langs :用于选择语言的模板
  • page : template for the ebook page :电子书的模板

Changing templates is really not advised, you should use plugins to only extend html,css,js using: https://github.com/GitbookIO/plugin/blob/master/index.js#L2 确实不建议更改模板,您应该使用插件仅通过以下方式扩展html,css,js: https//github.com/GitbookIO/plugin/blob/master/index.js#L2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM