diff --git a/index.js b/index.js
index 319b5770..9573dd81 100644
--- a/index.js
+++ b/index.js
@@ -46,6 +46,21 @@ var cache = {};
*/
var defaultTemplate = join(__dirname, 'public', 'directory.html');
+var templates = {
+ html: {
+ list: '
',
+ header: '',
+ item: '- '
+ + '{file.name}'
+ + '{file.size}'
+ + '{file.lastModified}'
+ + '
'
+ }
+}
/*!
* Stylesheet.
@@ -259,13 +274,8 @@ serveIndex.plain = function _plain(req, res, directory, nodes) {
*/
function createHtmlFileList(files, dirname, useIcons, view) {
- var html = ''
- + (view === 'details' ? (
- '') : '');
+ var html = templates.html.list.replace(/{view}/g, view)
+ + (view === 'details' ? templates.html.header : '');
html += files.map(function (file) {
var classes = [];
@@ -299,14 +309,12 @@ function createHtmlFileList(files, dirname, useIcons, view) {
? file.size
: '';
- return '- '
- + '' + escapeHtml(file.name) + ''
- + '' + escapeHtml(size) + ''
- + '' + escapeHtml(date) + ''
- + '
';
+ return templates.html.item
+ .replace(/{path}/g, escapeHtml(normalizeSlashes(normalize(path.join('/')))))
+ .replace(/{classes}/g, escapeHtml(classes.join(' ')))
+ .replace(/{file\.name}/g, escapeHtml(file.name))
+ .replace(/{file\.size}/g, escapeHtml(size))
+ .replace(/{file\.lastModified/g, escapeHtml(date))
}).join('\n');
html += '
';
@@ -325,10 +333,10 @@ function createHtmlRender(template) {
if (err) return callback(err);
var body = str
- .replace(/\{style\}/g, locals.style.concat(iconStyle(locals.fileList, locals.displayIcons)))
- .replace(/\{files\}/g, createHtmlFileList(locals.fileList, locals.directory, locals.displayIcons, locals.viewName))
- .replace(/\{directory\}/g, escapeHtml(locals.directory))
- .replace(/\{linked-path\}/g, htmlPath(locals.directory));
+ .replace(/{style}/g, locals.style.concat(iconStyle(locals.fileList, locals.displayIcons)))
+ .replace(/{files}/g, createHtmlFileList(locals.fileList, locals.directory, locals.displayIcons, locals.viewName))
+ .replace(/{directory}/g, escapeHtml(locals.directory))
+ .replace(/{linked-path}/g, htmlPath(locals.directory))
callback(null, body);
});