From a5cae6c4c0b09306c3125e7271b1b504a5b4c381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Padez?= Date: Thu, 7 May 2015 12:56:57 +0200 Subject: [PATCH 01/12] added trailingSlashes option --- index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index abf81a45..ff888c5c 100644 --- a/index.js +++ b/index.js @@ -89,7 +89,8 @@ exports = module.exports = function serveIndex(root, options){ , view = options.view || 'tiles' , filter = options.filter , template = options.template || defaultTemplate - , stylesheet = options.stylesheet || defaultStylesheet; + , stylesheet = options.stylesheet || defaultStylesheet + , trailingSlashes = options.trailingSlashes || false; return function serveIndex(req, res, next) { if (req.method !== 'GET' && req.method !== 'HEAD') { @@ -154,7 +155,7 @@ exports = module.exports = function serveIndex(root, options){ // not acceptable if (!type) return next(createError(406)); - exports[mediaType[type]](req, res, files, next, originalDir, showUp, icons, path, view, template, stylesheet); + exports[mediaType[type]](req, res, files, next, originalDir, showUp, icons, path, view, template, stylesheet, trailingSlashes); }); }); }; @@ -164,7 +165,7 @@ exports = module.exports = function serveIndex(root, options){ * Respond with text/html. */ -exports.html = function(req, res, files, next, dir, showUp, icons, path, view, template, stylesheet){ +exports.html = function(req, res, files, next, dir, showUp, icons, path, view, template, stylesheet, trailingSlashes){ fs.readFile(template, 'utf8', function(err, str){ if (err) return next(err); fs.readFile(stylesheet, 'utf8', function(err, style){ @@ -176,7 +177,7 @@ exports.html = function(req, res, files, next, dir, showUp, icons, path, view, t if (showUp) files.unshift({ name: '..' }); str = str .replace(/\{style\}/g, style.concat(iconStyle(files, icons))) - .replace(/\{files\}/g, html(files, dir, icons, view)) + .replace(/\{files\}/g, html(files, dir, icons, view, trailingSlashes)) .replace(/\{directory\}/g, escapeHtml(dir)) .replace(/\{linked-path\}/g, htmlPath(dir)); @@ -351,7 +352,7 @@ function iconStyle (files, useIcons) { * Map html `files`, returning an html unordered list. */ -function html(files, dir, useIcons, view) { +function html(files, dir, useIcons, view, trailingSlashes) { return '