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

Commit ef8f2a3

Browse files
committed
add localization for link label
1 parent 9c042a2 commit ef8f2a3

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Link target will be that page's source file on Github or Gitlab or any repo.
1212
3. Run `gitbook install`. It will automatically install `edit-this-page-link` gitbook plugin for your book. This is needed only once.
1313
4. Finally build your book (`gitbook build`) or serve (`gitbook serve`) as usual.
1414

15+
### Changing Link Label (Localization)
16+
17+
By default link label will be "Edit This Page". You can change it using plugin config `rtEditLinkLabel`.
18+
1519
## Sample `book.json` file
1620

1721
*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,7 +24,8 @@ Link target will be that page's source file on Github or Gitlab or any repo.
2024
{
2125
"plugins": ["edit-link"],
2226
"pluginsConfig": {
23-
"rtEditLinkBase": "https://github.com/USER/REPO/edit/BRANCH/path/to/book"
27+
"rtEditLinkBase": "https://github.com/USER/REPO/edit/BRANCH/path/to/book",
28+
"rtEditLinkLabel": "Edit This Page"
2429
}
2530
}
2631
```

index.js

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
module.exports = {
2-
book: {
3-
// assets: "./book",
4-
// js: [
5-
// "test.js"
6-
// ],
7-
// css: [
8-
// "test.css"
9-
// ],
10-
// html: {
11-
// "html:start": function() {
12-
// return "<!-- Start book "+this.options.title+" -->"
13-
// },
14-
// "html:end": function() {
15-
// return "<!-- End of book "+this.options.title+" -->"
16-
// },
17-
//
18-
// "head:start": "<!-- head:start -->",
19-
// "head:end": "<!-- head:end -->",
20-
//
21-
// "body:start": "<!-- body:start -->",
22-
// "body:end": "<!-- body:end -->"
23-
// }
24-
// },
252
hooks: {
263
// After html generation
274
"page:after": function(page) {
285

29-
page.content = page.content.replace(
6+
rtEditLinkBase = this.options.pluginsConfig.rtEditLinkBase;
7+
8+
if (typeof this.options.pluginsConfig.rtEditLinkLabel === 'undefined') {
9+
rtEditLinkLabel = "Edit This Page";
10+
} else {
11+
rtEditLinkLabel = this.options.pluginsConfig.rtEditLinkLabel;
12+
}
13+
14+
rtEditLink = '<a href="' + this.options.pluginsConfig.rtEditLinkBase + '/' + page.path + '" class="btn fa fa-edit pull-left">&nbsp;&nbsp;' + rtEditLinkLabel + '</a>';
15+
16+
page.content = page.content.replace (
3017
'<!-- Actions Right -->',
31-
'<a href="' + this.options.pluginsConfig.rtEditLinkBase + '/' + page.path + '" class="btn fa fa-edit pull-left"><b>Edit This Page on Github</b></a>' + '<!-- Actions Right -->'
32-
)
18+
rtEditLink + '<!-- Actions Right -->'
19+
)
3320

3421
return page;
3522
}

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": "0.1",
5+
"version": "1.0.0",
66
"author": "rtCamp <[email protected]>",
77
"contributors": [{
88
"name": "Rahul Bansal",

0 commit comments

Comments
 (0)