fix
This commit is contained in:
53
book/node_modules/honkit/lib/api/encodeProgress.js
generated
vendored
Normal file
53
book/node_modules/honkit/lib/api/encodeProgress.js
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const immutable_1 = __importDefault(require("immutable"));
|
||||
const encodeNavigation_1 = __importDefault(require("./encodeNavigation"));
|
||||
/**
|
||||
page.progress is a deprecated property from GitBook v2
|
||||
*/
|
||||
function encodeProgress(output, page) {
|
||||
const current = page.getPath();
|
||||
const navigation = immutable_1.default.Map((0, encodeNavigation_1.default)(output));
|
||||
const n = navigation.size;
|
||||
let percent = 0, prevPercent = 0, currentChapter = null;
|
||||
let done = true;
|
||||
const chapters = navigation
|
||||
.map((nav, chapterPath) => {
|
||||
nav.path = chapterPath;
|
||||
return nav;
|
||||
})
|
||||
.valueSeq()
|
||||
.sortBy((nav) => {
|
||||
return nav.index;
|
||||
})
|
||||
.map((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
|
||||
};
|
||||
}
|
||||
exports.default = encodeProgress;
|
Reference in New Issue
Block a user