11var path = require ( 'path' ) ;
22
33module . exports = {
4+ book : {
5+ assets : "./book" ,
6+ js : [ "plugin.js" ]
7+ } ,
48 hooks : {
59 // After html generation
6- "page:after " : function ( page ) {
10+ "page" : function ( page ) {
711 var config = this . options . pluginsConfig [ "edit-link" ] || { } ;
812
913 if ( ! config . base ) {
@@ -14,14 +18,30 @@ module.exports = {
1418 config . label = "Edit This Page" ;
1519 }
1620
17- newPath = path . relative ( this . options . originalInput , page . rawPath ) ;
21+ // add slash at the end if not present
22+ var base = config . base ;
23+ if ( base . slice ( - 1 ) != "/" ) {
24+ base = base + "/" ;
25+ }
26+
27+ // relative path to the page
28+ var newPath = path . relative ( this . root , page . rawPath ) ;
29+
30+ // language, if configured
31+ var lang = "" ;
32+ if ( this . context . config . language ) {
33+ lang = this . context . config . language + "/" ;
34+ }
1835
19- rtEditLink = '<a href="' + config . base + '/' + newPath + '" class="btn fa fa-edit pull-left"> ' + config . label + '</a>' ;
36+ rtEditLink = '<a id="edit-link" href="' + base + lang + newPath + '" class="btn fa fa-edit pull-left"> ' + config . label + '</a>' ;
2037
21- page . content = page . content . replace (
22- '<!-- Actions Right -->' ,
23- rtEditLink + '<!-- Actions Right -->'
24- )
38+ page . sections
39+ . filter ( function ( section ) {
40+ return section . type == 'normal' ;
41+ } )
42+ . forEach ( function ( section ) {
43+ section . content = rtEditLink + section . content ;
44+ } ) ;
2545
2646 return page ;
2747 }
0 commit comments