UNPKG

dirlist

Version:

A simple & old school directory listing middleware for node. Inspired by Apache's mod_autoindex.

74 lines (62 loc) 1.54 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style> </style> </head> <body> <h1 id="h1"></h1> <table id="table"> <tr> <th width="70%"> <a>Name</a> </th> <th align="center"> <a>Last modified</a> </th> <th> <a>Size</a> </th> </tr> <tr> <td colspan="3"><hr/></td> </tr> <tr> <td> <a href="../">Parent Directory<a> </td> <td></td> <td></td> </tr> </table> </body> <script> var dir = !@#$%; document.title = 'Index of '+dir.name; document.getElementById('h1').innerHTML = document.title; var children = dir.children; for(var i in children){ var file = children[i]; var size = file.size || '-'; if(file.size){ if(size<1024){ ; }else if(size>=1024 && size<1048576){ size = (Math.round(size/102.4)/10) +'K'; }else if (size>=1048576 && size<1073741824){ size = (Math.round(size/104857.6)/10) +'M'; } else { size = (Math.round(size/107374182.4)/10) +'G'; } } var html = '<tr><td><a href="'+file.name+(file.isFile?'':'/')+'">'+file.name+(file.isFile?'':'/')+'</a>'+ '</td><td align="center">'+file.lastModified.replace('T', ' at ').replace('Z', '').replace('.000','')+ '</td><td align="right">'+size+ '</td></tr>'; document.getElementById('table').innerHTML += html; } document.getElementById('table').innerHTML += '<tr><td colspan="3"><hr/></td></tr>' </script> </html>