gitbook-plugin-edit-link
Advanced tools
Comparing version 1.2.0 to 1.3.0
34
index.js
var path = require('path'); | ||
module.exports = { | ||
book: { | ||
assets: "./book", | ||
js: ["plugin.js"] | ||
}, | ||
hooks: { | ||
// After html generation | ||
"page:after": function(page) { | ||
"page": function(page) { | ||
var config = this.options.pluginsConfig["edit-link"] || {}; | ||
@@ -17,11 +21,27 @@ | ||
newPath = path.relative(this.options.originalInput, page.rawPath); | ||
// add slash at the end if not present | ||
var base = config.base; | ||
if(base.slice(-1) != "/") { | ||
base = base + "/"; | ||
} | ||
rtEditLink = '<a href="' + config.base + '/' + newPath + '" class="btn fa fa-edit pull-left"> ' + config.label + '</a>'; | ||
// relative path to the page | ||
var newPath = path.relative(this.root, page.rawPath); | ||
page.content = page.content.replace ( | ||
'<!-- Actions Right -->', | ||
rtEditLink + '<!-- Actions Right -->' | ||
) | ||
// language, if configured | ||
var lang = ""; | ||
if(this.context.config.language) { | ||
lang = this.context.config.language + "/"; | ||
} | ||
rtEditLink = '<a id="edit-link" href="' + base + lang + newPath + '" class="btn fa fa-edit pull-left"> ' + config.label + '</a>'; | ||
page.sections | ||
.filter(function(section) { | ||
return section.type == 'normal'; | ||
}) | ||
.forEach(function(section) { | ||
section.content = rtEditLink + section.content; | ||
}); | ||
return page; | ||
@@ -28,0 +48,0 @@ } |
{ | ||
"name": "gitbook-plugin-edit-link", | ||
"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.", | ||
"main": "index.js", | ||
"version": "1.2.0", | ||
"author": "rtCamp <admin@rtcamp.com>", | ||
"contributors": [{ | ||
"name": "Rahul Bansal", | ||
"email": "rahul.bansal@rtcamp.com" | ||
}], | ||
"engines": { | ||
"gitbook": "*" | ||
}, | ||
"homepage": "https://github.com/rtCamp/gitbook-plugin-edit-link", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/rtCamp/gitbook-plugin-edit-link.git" | ||
}, | ||
"license": "Apache 2", | ||
"bugs": { | ||
"url": "https://github.com/rtCamp/gitbook-plugin-edit-link/issues" | ||
}, | ||
"keywords": [ | ||
"gitbook", | ||
"plugin", | ||
"edit-with" | ||
] | ||
"name": "gitbook-plugin-edit-link", | ||
"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.", | ||
"main": "index.js", | ||
"version": "1.3.0", | ||
"author": "rtCamp <admin@rtcamp.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Rahul Bansal", | ||
"email": "rahul.bansal@rtcamp.com" | ||
} | ||
], | ||
"engines": { | ||
"gitbook": "*" | ||
}, | ||
"homepage": "https://github.com/rtCamp/gitbook-plugin-edit-link", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/rtCamp/gitbook-plugin-edit-link.git" | ||
}, | ||
"license": "Apache 2", | ||
"bugs": { | ||
"url": "https://github.com/rtCamp/gitbook-plugin-edit-link/issues" | ||
}, | ||
"keywords": [ | ||
"gitbook", | ||
"plugin", | ||
"edit-with", | ||
"github" | ||
] | ||
} |
@@ -20,6 +20,7 @@ GitBook Plugin: Edit Link | ||
#### Sample `book.json` file | ||
#### Sample `book.json` file for gitbook version 2.0.1 and above | ||
``` | ||
{ | ||
"gitbook": "2.0.1", | ||
"plugins": ["edit-link"], | ||
@@ -34,2 +35,18 @@ "pluginsConfig": { | ||
``` | ||
#### Sample `book.json` file for older gitbook versions <= 1.5.0 | ||
``` | ||
{ | ||
"gitbook": "1.5.0", | ||
"plugins": ["edit-link@1.1.0"], | ||
"pluginsConfig": { | ||
"edit-link": { | ||
"base": "https://github.com/USER/REPO/edit/BRANCH/path/to/book", | ||
"label": "Edit This Page" | ||
} | ||
} | ||
} | ||
``` | ||
**Note**: Above snippet can be used as complete `book.json` file, if your book doesn't have one yet. | ||
@@ -49,2 +66,12 @@ | ||
## Known Issue | ||
Gitbook 2.0.1 has removed `page:after` hook which this plugin needs. An issue has been reported here - https://github.com/GitbookIO/gitbook/issues/724 but meanwhile this plugin is using workaround added by this pull request - https://github.com/rtCamp/gitbook-plugin-edit-link/pull/4 | ||
So when using Gitbook 2.0.1, you may see following warning in console at the time of running build: | ||
> warn: hook 'page' used by plugin 'gitbook-plugin-edit-link' is deprecated, and will be remove in the coming versions | ||
You can safely ignore above warning for now. | ||
## How this work? | ||
@@ -58,5 +85,9 @@ | ||
**1.3 - 28 April 2015** | ||
- Gitbook 2.0.1 compatibility added by [@todvora](https://github.com/rtCamp/gitbook-plugin-edit-link/pull/4). Please see [Known Issue](https://github.com/rtCamp/gitbook-plugin-edit-link#known-issue) section for more details. | ||
**1.2 - 03 April 2015** | ||
- Multiligual gitbook support added by [@aniav](https://github.com/aniav) ([#2](https://github.com/rtCamp/gitbook-plugin-edit-link/pull/2)) | ||
- Multilingual gitbook support added by [@aniav](https://github.com/aniav) ([#2](https://github.com/rtCamp/gitbook-plugin-edit-link/pull/2)) | ||
@@ -63,0 +94,0 @@ **1.1.3 - 11 Jan 2015** |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
18016
6
45
93
1