diff --git a/lib/helpers.js b/lib/helpers.js index 562101f..144781d 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -83,19 +83,74 @@ helpers.filesToTree = function(files){ } +// +// Function to use with sorting the ToC. +// +helpers.tocSort = function (a, b) { + // For future reference, here is the list from the top-level. + /*[ + 'cryptography', + 'advanced', + 'intermediate', + 'errors', + 'file-system', + 'javascript-conventions', + 'child-processes', + 'command-line', + 'REPL', + 'getting-started', + 'HTTP' ] + */ + + // These items should be listed *first*. + var first = [ + 'getting-started', + 'javascript-conventions' + ]; + + // These items should be listed *last*. + var last = [ + 'intermediate', + 'advanced', + 'cryptography' + ]; + + //a > b: --> 1 + + // Handles the case where a and/or b is in the "first" list. + if ( -~first.indexOf(a) || -~first.indexOf(b) ) { + + return ( -~first.indexOf(a) && -~first.indexOf(b) ) + ? (first.indexOf(a) - first.indexOf(b)) + : ( -~first.indexOf(a) ? -1 : 1); + + } + + if ( -~last.indexOf(a) || -~last.indexOf(b) ) { + return (-~last.indexOf(a) && -~last.indexOf(b)) + ? (last.indexOf(a) - last.indexOf(b)) + : ( -~last.indexOf(a) ? 1 : -1); + } + + return a > b ? 1 : (a < b ? -1 : 0); +}; + helpers.treeToHTML = function(values, parent) { - var str = '