gitbook-plugin-edit-link
Advanced tools
Comparing version 1.2.0 to 1.2.1
41
index.js
var path = require('path'); | ||
module.exports = { | ||
book: { | ||
assets: "./book", | ||
js: ["plugin.js"], | ||
css: ["plugin.css"] | ||
}, | ||
hooks: { | ||
// After html generation | ||
"page:after": function(page) { | ||
"page": function(page) { | ||
if(this.config.options.generator !== 'website') { | ||
return page; | ||
} | ||
var config = this.options.pluginsConfig["edit-link"] || {}; | ||
@@ -13,15 +22,29 @@ | ||
if (!config.label) { | ||
config.label = "Edit This Page"; | ||
var label = (config.label && config.label[this.context.config.language]) || config.label || "Edit This Page"; | ||
// add slash at the end if not present | ||
var base = config.base; | ||
if(base.slice(-1) != "/") { | ||
base = base + "/"; | ||
} | ||
newPath = path.relative(this.options.originalInput, page.rawPath); | ||
// relative path to the page | ||
var newPath = path.relative(this.root, page.rawPath); | ||
rtEditLink = '<a href="' + config.base + '/' + newPath + '" class="btn fa fa-edit pull-left"> ' + config.label + '</a>'; | ||
// language, if configured | ||
var lang = ""; | ||
if(this.context.config.language) { | ||
lang = this.context.config.language + "/"; | ||
} | ||
page.content = page.content.replace ( | ||
'<!-- Actions Right -->', | ||
rtEditLink + '<!-- Actions Right -->' | ||
) | ||
rtEditLink = '<a id="edit-link" href="' + base + lang + newPath + '" class="btn fa fa-edit pull-left"> ' + label + '</a>'; | ||
page.sections | ||
.filter(function(section) { | ||
return section.type == 'normal'; | ||
}) | ||
.forEach(function(section) { | ||
section.content = rtEditLink + section.content; | ||
}); | ||
return page; | ||
@@ -28,0 +51,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": "*" | ||
"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.1", | ||
"author": "rtCamp <admin@rtcamp.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Rahul Bansal", | ||
"email": "rahul.bansal@rtcamp.com" | ||
}, | ||
"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": "Samy Pessé", | ||
"email": "samy@gitbook.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,36 @@ "pluginsConfig": { | ||
``` | ||
#### Sample `book.json` file for gitbook version 2.0.1+ and multilingual labels | ||
``` | ||
{ | ||
"gitbook": "2.0.1", | ||
"plugins": ["edit-link"], | ||
"pluginsConfig": { | ||
"edit-link": { | ||
"base": "https://github.com/USER/REPO/edit/BRANCH/path/to/book", | ||
"label": { | ||
"en": "Edit This Page", | ||
"de": "Seite bearbeiten" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
#### 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 +84,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,2 +103,6 @@ | ||
**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-issues for more details. | ||
**1.2 - 03 April 2015** | ||
@@ -60,0 +109,0 @@ |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
18841
7
59
111
1