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

plugin compatibility with the gitbook 2.0.1 #4

Merged
merged 1 commit into from
Apr 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions book/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require(["gitbook"], function(gitbook) {
gitbook.events.bind("page.change", function() {
// move the edit link to the header, after font-setting icon
$(document.getElementById("edit-link")).insertAfter("#font-settings-wrapper");
});
});
34 changes: 27 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
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"] || {};

if (!config.base) {
Expand All @@ -14,14 +18,30 @@ module.exports = {
config.label = "Edit This Page";
}

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 + "/";
}

// relative path to the page
var newPath = path.relative(this.root, page.rawPath);

// language, if configured
var lang = "";
if(this.context.config.language) {
lang = this.context.config.language + "/";
}

rtEditLink = '<a href="' + config.base + '/' + newPath + '" class="btn fa fa-edit pull-left">&nbsp;&nbsp;' + config.label + '</a>';
rtEditLink = '<a id="edit-link" href="' + base + lang + newPath + '" class="btn fa fa-edit pull-left">&nbsp;&nbsp;' + config.label + '</a>';

page.content = page.content.replace (
'<!-- Actions Right -->',
rtEditLink + '<!-- Actions Right -->'
)
page.sections
.filter(function(section) {
return section.type == 'normal';
})
.forEach(function(section) {
section.content = rtEditLink + section.content;
});

return page;
}
Expand Down