mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
25 lines
641 B
JavaScript
25 lines
641 B
JavaScript
var _ = require("lodash");
|
|
var links = require("./links");
|
|
|
|
function normalizeChapters(chapterList, level, base) {
|
|
var i = base || 0;
|
|
return _.map(chapterList, function(chapter) {
|
|
chapter.level = (level? [level || "", i] : [i]).join(".");
|
|
chapter.exteral = links.isExternal(chapter.path);
|
|
chapter.article = normalizeChapters(chapter.articles || [], chapter.level, 1);
|
|
|
|
i = i + 1;
|
|
return chapter;
|
|
});
|
|
};
|
|
|
|
function normalizeSummary(summary) {
|
|
if (_.isArray(summary)) summary = { chapters: summary };
|
|
summary.chapters = normalizeChapters(summary.chapters);
|
|
return summary;
|
|
};
|
|
|
|
module.exports = {
|
|
normalize: normalizeSummary
|
|
};
|