前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >gitbook 入门教程之增强版 edit-link-plus 编辑此页插件

gitbook 入门教程之增强版 edit-link-plus 编辑此页插件

作者头像
雪之梦技术驿站
发布2019-12-12 14:59:08
发布2019-12-12 14:59:08
1K00
代码可运行
举报
运行总次数:0
代码可运行

Gitbook plugin add "edit this page" link, and intelligent recognition to Github or Gitlab source repository.

? Homepage

Screenshot

Usage

Step #1 - Update book.json file

  1. In you gitbook's book.json file, add edit-link-plus to plugins list.
  2. In pluginsConfig, Set base value which is base path to your github or gitlab or other code repo. Trailing slash is NOT required.
  3. By default link label will be "Edit This Page". You can change it using plugin config label.
  4. In pluginsConfig, Set defaultBase value which is set as default base path to your github or gitlab or other code repo. Trailing slash is also NOT required.

Here is simplest example :

代码语言:javascript
代码运行次数:0
复制
{
    "plugins": ["edit-link-plus"],
    "pluginsConfig": {
        "edit-link-plus": {
            "base": "https://github.com/USER/REPO/edit/BRANCH/path/to/book"
        }
    }
}

In addition, the supported configuration options are as follows :

代码语言:javascript
代码运行次数:0
复制
"base": {
  "type": [
    "string",
    "object"
  ],
  "title": "Base for the edit redirection",
  "required": true
},
"defaultBase": {
  "type": "string",
  "title": "Default base for the edit redirection",
  "required": false
},
"label": {
  "type": [
    "string",
    "object"
  ],
  "title": "Label for the edit button",
  "default": "Edit This Page",
  "required": false
}

Step #2 - gitbook commands

  1. Run gitbook install. It will automatically install edit-link-plus gitbook plugin for your book. This is needed only once.
代码语言:javascript
代码运行次数:0
复制
gitbook install

or you can run npm install gitbook-plugin-edit-link-plus to install locally.

代码语言:javascript
代码运行次数:0
复制
npm install gitbook-plugin-edit-link-plus
  1. Build your book (gitbook build) or serve (gitbook serve) as usual.
代码语言:javascript
代码运行次数:0
复制
gitbook serve

Example

  • Official documentation configuration file

> https://github.com/snowdreams1006/gitbook-plugin-edit-link-plus/blob/master/docs/book.json

代码语言:javascript
代码运行次数:0
复制
{
    "plugins": ["edit-link-plus"],
    "pluginsConfig": {
        "edit-link-plus": {
            "base": {
              "snowdreams1006.github.io":"https://github.com/snowdreams1006/gitbook-plugin-edit-link-plus/edit/master/docs",
              "snowdreams1006.gitlab.io":"https://gitlab.com/snowdreams1006/gitbook-plugin-edit-link-plus/edit/master/docs",
              "snowdreams1006.gitee.io":"https://gitee.com/snowdreams1006/gitbook-plugin-edit-link-plus/edit/master/docs"
            },
            "defaultBase": "https://github.com/snowdreams1006/gitbook-plugin-edit-link-plus/edit/master/docs",
            "label": "Edit This Page"
        }
    }
}
  • Official example configuration file

> https://github.com/snowdreams1006/gitbook-plugin-edit-link-plus/blob/master/example/book.json

代码语言:javascript
代码运行次数:0
复制
{
    "plugins": ["edit-link-plus"],
    "pluginsConfig": {
        "edit-link-plus": {
            "base": "https://github.com/snowdreams1006/gitbook-plugin-edit-link-plus/edit/master/example"
        }
    }
}

Sample book.json file

代码语言:javascript
代码运行次数:0
复制
{
    "plugins": ["edit-link-plus"],
    "pluginsConfig": {
        "edit-link-plus": {
            "base": "https://github.com/USER/REPO/edit/BRANCH/path/to/book"
        }
    }
}

or you can add label to custom your label:

代码语言:javascript
代码运行次数:0
复制
{
    "plugins": ["edit-link-plus"],
    "pluginsConfig": {
        "edit-link-plus": {
            "base": "https://github.com/USER/REPO/edit/BRANCH/path/to/book",
            "label": "点我反馈"
        }
    }
}

Sample book.json file for Multi-source base

代码语言:javascript
代码运行次数:0
复制
{
    "plugins": ["edit-link-plus"],
    "pluginsConfig": {
        "edit-link-plus": {
            "base": {
              "USER.github.io":"https://github.com/USER/REPO/edit/BRANCH/path/to/book",
              "USER.gitlab.io":"https://gitlab.com/USER/REPO/edit/BRANCH/path/to/book",
              "USER.gitee.io":"https://gitee.com/USER/REPO/edit/BRANCH/path/to/book",
              "CUSTOME DOMAIN":"https://github.com/snowdreams1006/gitbook-plugin-edit-link-plus/edit/master/docs"
            },
            "defaultBase": "https://github.com/USER/REPO/edit/BRANCH/path/to/book",
            "label": "Edit This Page"
        }
    }
}

Sample book.json file for multilingual labels

代码语言:javascript
代码运行次数:0
复制
{
    "plugins": ["edit-link-plus"],
    "pluginsConfig": {
        "edit-link-plus": {
            "base": "https://github.com/USER/REPO/edit/BRANCH/path/to/book",
            "label": {
                "en": "Edit This Page",
                "zh": "编辑本页"
            }
        }
    }
}

Note: Above snippet can be used as complete book.json file, if your book doesn't have one yet.

Github/Gitlab: In string ...REPO/edit/BRANCH..., you may replace edit with tree if you want source file to open in read-mode, rather than edit-mode directly on github/gitlab.

Author

? snowdreams1006

Contributing

Contributions, issues and feature requests are welcome!<br>Feel free to check issues page.

Show your support

Give a Star if this project helped you!

Copyright

Copyright © 2019 snowdreams1006.

This project is MIT licensed.

Thanks

Troubleshooting

  1. If you are not seeing the "Edit this page" link, check if your book.json is valid. You can use this online tool - http://json.parser.online.fr/beta/
  2. Check if you are using default gitbook theme. It is NOT recommended to modify gitbook themes directly.
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ? Homepage
  • Screenshot
  • Usage
    • Step #1 - Update book.json file
    • Step #2 - gitbook commands
  • Example
    • Sample book.json file
    • Sample book.json file for Multi-source base
    • Sample book.json file for multilingual labels
  • Author
  • Contributing
  • Show your support
  • Copyright
  • Thanks
  • Troubleshooting
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档