Skip to content
This repository was archived by the owner on Oct 27, 2020. It is now read-only.

Commit d60e0e7

Browse files
committed
updated config as per suggestions in #1
1 parent 55ddab1 commit d60e0e7

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,39 @@ This GitBook Plugin adds "Edit This Page" link on every page.
55

66
Link target will be that page's source file on Github or Gitlab or any repo.
77

8-
## Usage
8+
## Screenshot
99

10-
1. In you gitbook's `book.json` file, add `edit-link` to `plugins` list.
11-
2. Set `rtEditLinkBase` value which is base path to your github or gitlab or other code repo. Trailing slash is NOT required.
12-
3. Run `gitbook install`. It will automatically install `edit-this-page-link` gitbook plugin for your book. This is needed only once.
13-
4. Finally build your book (`gitbook build`) or serve (`gitbook serve`) as usual.
10+
![gitbook-plugin-edit-link](https://cloud.githubusercontent.com/assets/4115/5695161/f5b79002-99b8-11e4-821a-d2af6c729348.png)
1411

15-
### Changing Link Label (Localization)
12+
## Usage
1613

17-
By default link label will be "Edit This Page". You can change it using plugin config `rtEditLinkLabel`.
14+
### Step #1 - Update `book.json` file
1815

19-
## Sample `book.json` file
16+
1. In you gitbook's `book.json` file, add `edit-link` to `plugins` list.
17+
2. In `pluginsConfig`, Set `base` value which is base path to your github or gitlab or other code repo. Trailing slash is NOT required.
18+
3. By default link label will be "Edit This Page". You can change it using plugin config `label`.
2019

21-
*Important*: Make sure you edit value of `rtEditLinkBase`. You can replace `edit` with `tree` if you want source file to open in read-mode, rather than edit-mode directly on github/gitlab.
20+
#### Sample `book.json` file
2221

2322
```
2423
{
2524
"plugins": ["edit-link"],
2625
"pluginsConfig": {
27-
"rtEditLinkBase": "https://github.com/USER/REPO/edit/BRANCH/path/to/book",
28-
"rtEditLinkLabel": "Edit This Page"
26+
"edit-link": {
27+
"base": "https://github.com/USER/REPO/edit/BRANCH/path/to/book",
28+
"label": "Edit This Page"
29+
}
2930
}
3031
}
3132
```
33+
**Important**: Make sure you edit value of `edit-link => base`. You can replace `edit` with `tree` if you want source file to open in read-mode, rather than edit-mode directly on github/gitlab.
3234

33-
Above snippet can be used as complete `book.json` file, if your book doesn't have one yet.
34-
35-
## Screenshot
35+
**Note**: Above snippet can be used as complete `book.json` file, if your book doesn't have one yet.
3636

37-
![gitbook-plugin-edit-link](https://cloud.githubusercontent.com/assets/4115/5695161/f5b79002-99b8-11e4-821a-d2af6c729348.png)
37+
### Step #2 - gitbook commands
3838

39+
1. Run `gitbook install`. It will automatically install `edit-link` gitbook plugin for your book. This is needed only once.
40+
2. Build your book (`gitbook build`) or serve (`gitbook serve`) as usual.
3941

4042
## Troubleshooting
4143

@@ -44,6 +46,6 @@ Above snippet can be used as complete `book.json` file, if your book doesn't hav
4446

4547
## How this work?
4648

47-
This plugin simply looks for HTML comment `<!-- Actions Right -->` in parsed page content and insert "edit link" HTML right after it (HTML comment).
49+
This plugin simply looks for HTML comment `<!-- Actions Right -->` in parsed page content and insert "edit link" HTML just before `<!-- Actions Right -->`.
4850

49-
This means if that HTML comment changes, this plugin will break (I hope to fix it easily whenever that happen).
51+
This means if that HTML comment changes, this plugin will break but I hope to fix it easily whenever that happen.

index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ module.exports = {
22
hooks: {
33
// After html generation
44
"page:after": function(page) {
5+
var config = this.options.pluginsConfig["edit-link"] || {};
56

6-
rtEditLinkBase = this.options.pluginsConfig.rtEditLinkBase;
7+
if (!config.base) {
8+
throw "ERROR: 'base' value required to generate 'Edit This Page' link. \nFor help, please refer to - https://github.com/rtCamp/gitbook-plugin-edit-link/blob/master/README.md#usage";
9+
}
710

8-
if (typeof this.options.pluginsConfig.rtEditLinkLabel === 'undefined') {
9-
rtEditLinkLabel = "Edit This Page";
10-
} else {
11-
rtEditLinkLabel = this.options.pluginsConfig.rtEditLinkLabel;
11+
if (!config.label) {
12+
config.label = "Edit This Page";
1213
}
1314

14-
rtEditLink = '<a href="' + this.options.pluginsConfig.rtEditLinkBase + '/' + page.path + '" class="btn fa fa-edit pull-left">&nbsp;&nbsp;' + rtEditLinkLabel + '</a>';
15+
rtEditLink = '<a href="' + config.base + '/' + page.path + '" class="btn fa fa-edit pull-left">&nbsp;&nbsp;' + config.label + '</a>';
1516

1617
page.content = page.content.replace (
1718
'<!-- Actions Right -->',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gitbook-plugin-edit-link",
33
"description": "GitBook Plugin to add \"Edit this page\" link on every page. Link target will be that page's source file on Github or Gitlab or any repo.",
44
"main": "index.js",
5-
"version": "1.1.1",
5+
"version": "1.1.2",
66
"author": "rtCamp <[email protected]>",
77
"contributors": [{
88
"name": "Rahul Bansal",

0 commit comments

Comments
 (0)