// Given an array of documents, constructs a tree of items // // The tree is built based on the doc.path array that's in every // document. function makeNavTree(parent, docs, depth) { var items = []; for (var i = 0; i < docs.length; i++) { var doc = docs[i]; var name = doc.path[depth]; if (name == 'index.md') { if (parent != null) { parent.doc = doc; } continue; } // find or create a node for the current doc var item = null; for (var j = 0; j < items.length; j++) { if (items[j].name === name) { item = items[j]; break; } } if (item === null) { // not found, create a fresh node item = {name: name, doc: null, children: []}; items.push(item); } if (doc.path.length > depth + 1) { // if there are additional path elements, this means the doc // belongs lower in the hierarchy, so treat it as a child. item.children.push(doc); } else { // this node is home to this doc item.doc = doc; } } for (i = 0; i < items.length; i++) { item = items[i]; item.children = makeNavTree(item, item.children, depth + 1); } items.sort(function(a, b) { if (a.doc.order < b.doc.order) { return -1; } else if (a.doc.order > b.doc.order) { return 1; } return 0; }); return items; } function outputNavBarTree(items) { document.writeln("