Sha256: acab8edb601d928e42b9b20efc3145c2051ec6e12f88f1c141139681e25bf6ef
Contents?: true
Size: 1.22 KB
Versions: 2
Compression:
Stored size: 1.22 KB
Contents
(function(){ //load data let menu = document.getElementById('menu'); var array = menu.innerHTML.split("\n") //remove empty (whitespace) strings var filtered = array.filter(function(str) { return /\S/.test(str); }); //remove whitespace in strings and split by forward slash paths = filtered.map(function(e){return e.trim();}); var hierarchy = paths.reduce(function(hier,path){ var x = hier; path.split('/').forEach(function(item){ if(!x[item]){ x[item] = {}; } x = x[item]; }); x.path = path; return hier; }, {}); var makeul = function(hierarchy, classname){ var dirs = Object.keys(hierarchy); var ul = '<ul'; if(classname){ ul += ' class="' + classname + '"'; } ul += '>\n'; dirs.forEach(function(dir){ var path = hierarchy[dir].path; if(path){ // file ul += '<li class="file" data-url="' + path + '">' + dir + '</li>\n'; }else{ ul += '<li class="folder">' + dir + '\n'; ul += makeul(hierarchy[dir]); ul += '</li>\n'; } }); ul += '</ul>\n'; return ul; }; var ul = makeul(hierarchy, 'collapsibleList'); document.getElementById('renderList').innerHTML = ul; })();
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
jekyll-notes-0.1.1 | assets/js/GenerateMenu.js.save.1 |
jekyll-notes-0.1.0 | assets/js/GenerateMenu.js.save.1 |