diff options
Diffstat (limited to 'lib/plugins/compatibility.js')
-rw-r--r-- | lib/plugins/compatibility.js | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/plugins/compatibility.js b/lib/plugins/compatibility.js index eb64e48..8fddba6 100644 --- a/lib/plugins/compatibility.js +++ b/lib/plugins/compatibility.js @@ -12,7 +12,12 @@ function pluginCtx(plugin) { return ctx; } -// Call a function "fn" with a context of page similar to the one in GitBook v2 +/* + Call a function "fn" with a context of page similar to the one in GitBook v2 + + @params {Page} + @returns {String|undefined} new content of the page +*/ function pageHook(page, fn) { // Get page context var ctx = page.getContext().page; @@ -24,19 +29,26 @@ function pageHook(page, fn) { // Deprecate sections error.deprecateField(ctx, 'sections', [ - { content: ctx.content } + { content: ctx.content, type: 'normal' } ], '"sections" property is deprecated, use page.content instead'); return fn(ctx) .then(function(result) { + // No returned value + // Existing content will be used if (!result) return undefined; - if (result.content) { - return result.content; - } + // GitBook 2 compatibility first + // Use sections if provided if (result.sections) { return _.pluck(result.sections, 'content').join('\n'); } + + // GitBook 3 + // Use returned page.content + if (result.content) { + return result.content; + } }); } |