document.addEventListener("DOMContentLoaded", function(){ for (list of document.getElementsByClassName('list')) { if (list.summary === "tree listing") { const table = list.children[0] const rows = table.children // Reorder directories (and submodules) before files // This is done here instead of during page generation for two reasons: // 1. Implementing it in generation would be difficult, since the logic // is done by a git function // 2. It could be argued if your browser doesn't support javascript, // navigation would be easier if everything is ordered normally var lastDir = rows[1].getAttribute('summary') == '----------' ? 2 : 1 for (let i = 1; i < rows.length; ++i) { if (!rows[i].getAttribute('summary').startsWith('-')) { if (i > lastDir) { table.insertBefore(rows[i], rows[lastDir]) } ++lastDir } } } } });