summaryrefslogtreecommitdiffstats
path: root/lib/api/encodeNavigation.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/encodeNavigation.js')
-rw-r--r--lib/api/encodeNavigation.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/api/encodeNavigation.js b/lib/api/encodeNavigation.js
index c48ba50..8e329a1 100644
--- a/lib/api/encodeNavigation.js
+++ b/lib/api/encodeNavigation.js
@@ -1,3 +1,4 @@
+var Immutable = require('immutable');
/**
Encode an article for next/prev
@@ -26,13 +27,15 @@ function encodeArticle(pages, article) {
*/
function encodeNavigation(output) {
var book = output.getBook();
+ var pages = output.getPages();
var summary = book.getSummary();
var articles = summary.getArticlesAsList();
- return articles
+
+ var navigation = articles
.map(function(article, i) {
var ref = article.getRef();
- if (ref) {
+ if (!ref) {
return undefined;
}
@@ -45,14 +48,17 @@ function encodeNavigation(output) {
index: i,
title: article.getTitle(),
introduction: (i === 0),
- prev: prev? encodeArticle(prev) : undefined,
- next: next? encodeArticle(next) : undefined,
+ prev: prev? encodeArticle(pages, prev) : undefined,
+ next: next? encodeArticle(pages, next) : undefined,
level: article.getLevel()
}
];
})
- .toMap()
- .toJS();
+ .filter(function(e) {
+ return Boolean(e);
+ });
+
+ return Immutable.Map(navigation).toJS();
}
module.exports = encodeNavigation;