summaryrefslogtreecommitdiffstats
path: root/lib/api/encodeProgress.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-09-05 11:04:18 +0200
committerSamy Pessé <samypesse@gmail.com>2016-09-05 11:04:18 +0200
commita14ca3e268e95a7eab59fb205b41da7331d57631 (patch)
tree9c84b2cbd561345335fca3e26af961b2ea23d8ec /lib/api/encodeProgress.js
parent9c071dade573aa6990878006f83c89b6065a1395 (diff)
downloadgitbook-a14ca3e268e95a7eab59fb205b41da7331d57631.zip
gitbook-a14ca3e268e95a7eab59fb205b41da7331d57631.tar.gz
gitbook-a14ca3e268e95a7eab59fb205b41da7331d57631.tar.bz2
Switch to lerna
Diffstat (limited to 'lib/api/encodeProgress.js')
-rw-r--r--lib/api/encodeProgress.js63
1 files changed, 0 insertions, 63 deletions
diff --git a/lib/api/encodeProgress.js b/lib/api/encodeProgress.js
deleted file mode 100644
index afa0341..0000000
--- a/lib/api/encodeProgress.js
+++ /dev/null
@@ -1,63 +0,0 @@
-var Immutable = require('immutable');
-var encodeNavigation = require('./encodeNavigation');
-
-/**
- page.progress is a deprecated property from GitBook v2
-
- @param {Output}
- @param {Page}
- @return {Object}
-*/
-function encodeProgress(output, page) {
- var current = page.getPath();
- var navigation = encodeNavigation(output);
- navigation = Immutable.Map(navigation);
-
- var n = navigation.size;
- var percent = 0, prevPercent = 0, currentChapter = null;
- var done = true;
-
- var chapters = navigation
- .map(function(nav, chapterPath) {
- nav.path = chapterPath;
- return nav;
- })
- .valueSeq()
- .sortBy(function(nav) {
- return nav.index;
- })
- .map(function(nav, i) {
- // Calcul percent
- nav.percent = (i * 100) / Math.max((n - 1), 1);
-
- // Is it done
- nav.done = done;
- if (nav.path == current) {
- currentChapter = nav;
- percent = nav.percent;
- done = false;
- } else if (done) {
- prevPercent = nav.percent;
- }
-
- return nav;
- })
- .toJS();
-
- return {
- // Previous percent
- prevPercent: prevPercent,
-
- // Current percent
- percent: percent,
-
- // List of chapter with progress
- chapters: chapters,
-
- // Current chapter
- current: currentChapter
- };
-}
-
-module.exports = encodeProgress;
-