diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-04-26 17:02:59 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-04-26 17:02:59 +0200 |
commit | 8bac111acf121adf03cc2dff09bd0a1ce8cea19b (patch) | |
tree | e568a585c6ac78b05ff86044fb589edbd778b43d /lib/api/encodePage.js | |
parent | 7a46d3b4977bcd1e115324880a409e88032899a7 (diff) | |
download | gitbook-8bac111acf121adf03cc2dff09bd0a1ce8cea19b.zip gitbook-8bac111acf121adf03cc2dff09bd0a1ce8cea19b.tar.gz gitbook-8bac111acf121adf03cc2dff09bd0a1ce8cea19b.tar.bz2 |
Add base for plugin JS api
Diffstat (limited to 'lib/api/encodePage.js')
-rw-r--r-- | lib/api/encodePage.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/api/encodePage.js b/lib/api/encodePage.js index 9ec55bc..98d7409 100644 --- a/lib/api/encodePage.js +++ b/lib/api/encodePage.js @@ -1,3 +1,5 @@ +var JSONUtils = require('../json'); +var deprecate = require('./deprecate'); /** Encode a page in a context to a JS API @@ -7,8 +9,26 @@ @return {Object} */ function encodePage(output, page) { + var book = output.getBook(); + var summary = book.getSummary(); + var fs = book.getContentFS(); + var file = page.getFile(); + // JS Page is based on the JSON output + var result = JSONUtils.encodePage(page, summary); + result.type = file.getType(); + result.path = file.getPath(); + result.rawPath = fs.resolve(result.path); + + deprecate.field(output, 'page.section', result, 'sections', [ + { + content: result.content, + type: 'normal' + } + ], '"sections" property is deprecated, use page.content instead'); + + return result; } module.exports = encodePage; |