summaryrefslogtreecommitdiffstats
path: root/lib/json/encodePage.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-04-28 14:28:41 +0200
committerSamy Pessé <samypesse@gmail.com>2016-04-28 14:28:41 +0200
commitf946650ddb6b075aa626cc165b7b9ea53924a5b1 (patch)
tree44a1b2f31ea28ab1cba9c956026fb35f667d14b9 /lib/json/encodePage.js
parent14fd6bbdce87a8b4c60a9dc571608428d738aafc (diff)
downloadgitbook-f946650ddb6b075aa626cc165b7b9ea53924a5b1.zip
gitbook-f946650ddb6b075aa626cc165b7b9ea53924a5b1.tar.gz
gitbook-f946650ddb6b075aa626cc165b7b9ea53924a5b1.tar.bz2
Add "next" and "previous" to page JSON repr
Diffstat (limited to 'lib/json/encodePage.js')
-rw-r--r--lib/json/encodePage.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/json/encodePage.js b/lib/json/encodePage.js
index d876c78..be92117 100644
--- a/lib/json/encodePage.js
+++ b/lib/json/encodePage.js
@@ -1,3 +1,5 @@
+var encodeSummaryArticle = require('./encodeSummaryArticle');
+
/**
Return a JSON representation of a page
@@ -10,7 +12,6 @@ function encodePage(page, summary) {
var attributes = page.getAttributes();
var article = summary.getByPath(file.getPath());
-
var result = attributes.toJS();
if (article) {
@@ -18,7 +19,15 @@ function encodePage(page, summary) {
result.level = article.getLevel();
result.depth = article.getDepth();
- // todo: next and prev
+ var nextArticle = summary.getNextArticle(article);
+ if (nextArticle) {
+ result.next = encodeSummaryArticle(nextArticle);
+ }
+
+ var prevArticle = summary.getPrevArticle(article);
+ if (prevArticle) {
+ result.previous = encodeSummaryArticle(prevArticle);
+ }
}
result.content = page.getContent();