diff options
author | Johan Preynat <johan.preynat@gmail.com> | 2016-04-19 10:02:41 +0200 |
---|---|---|
committer | Johan Preynat <johan.preynat@gmail.com> | 2016-04-19 10:02:41 +0200 |
commit | 3c54c89464e51986c952dd1ab313e4e2e10382f8 (patch) | |
tree | e666afbe0a72e067717bf49e625ca889be6379c5 /lib/plugins | |
parent | d07aa13822230ee5086bafcb9ea16cb8447fb562 (diff) | |
download | gitbook-3c54c89464e51986c952dd1ab313e4e2e10382f8.zip gitbook-3c54c89464e51986c952dd1ab313e4e2e10382f8.tar.gz gitbook-3c54c89464e51986c952dd1ab313e4e2e10382f8.tar.bz2 |
Use page.content if modified or fallback to page.sections in plugins hooks
Diffstat (limited to 'lib/plugins')
-rw-r--r-- | lib/plugins/compatibility.js | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/plugins/compatibility.js b/lib/plugins/compatibility.js index 8fddba6..77f4be2 100644 --- a/lib/plugins/compatibility.js +++ b/lib/plugins/compatibility.js @@ -32,23 +32,26 @@ function pageHook(page, fn) { { content: ctx.content, type: 'normal' } ], '"sections" property is deprecated, use page.content instead'); + // Keep reference of original content for compatibility + var originalContent = ctx.content; + return fn(ctx) .then(function(result) { // No returned value // Existing content will be used if (!result) return undefined; - // 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) { + // Use returned page.content if different from original content + if (result.content != originalContent) { return result.content; } + + // GitBook 2 compatibility + // Finally, use page.sections + if (result.sections) { + return _.pluck(result.sections, 'content').join('\n'); + } }); } |