blob: c48ba5011c329f7b23e5d8ecbc5a468304ab84cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/**
Encode an article for next/prev
@param {Map<String:Page>}
@param {Article}
@return {Object}
*/
function encodeArticle(pages, article) {
var articlePath = article.getPath();
return {
path: articlePath,
title: article.getTitle(),
level: article.getLevel(),
exists: (articlePath && pages.has(articlePath)),
external: article.isExternal()
};
}
/**
this.navigation is a deprecated property from GitBook v2
@param {Output}
@return {Object}
*/
function encodeNavigation(output) {
var book = output.getBook();
var summary = book.getSummary();
var articles = summary.getArticlesAsList();
return articles
.map(function(article, i) {
var ref = article.getRef();
if (ref) {
return undefined;
}
var prev = articles.get(i - 1);
var next = articles.get(i + 1);
return [
ref,
{
index: i,
title: article.getTitle(),
introduction: (i === 0),
prev: prev? encodeArticle(prev) : undefined,
next: next? encodeArticle(next) : undefined,
level: article.getLevel()
}
];
})
.toMap()
.toJS();
}
module.exports = encodeNavigation;
|