Skip to content

Commit

Permalink
link directories in page headings in directory middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
adammw authored and tj committed Jul 2, 2011
1 parent 315388e commit b4898dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion lib/middleware/directory.js
Expand Up @@ -101,7 +101,8 @@ exports.html = function(req, res, files, next, dir, showUp, icons){
str = str
.replace('{style}', style)
.replace('{files}', html(files, dir, icons))
.replace(/\{directory\}/g, dir);
.replace('{directory}', dir)
.replace('{linked-path}', htmlPath(dir));
res.setHeader('Content-Type', 'text/html');
res.setHeader('Content-Length', str.length);
res.end(str);
Expand Down Expand Up @@ -131,6 +132,21 @@ exports.plain = function(req, res, files){
res.end(files);
};

/**
* Map html `directory`, returning a linked path
*/

function htmlPath(path) {
var tempPath = [];
return '<a href="/">/</a> ' + path.split('/').slice(1).map(function(dir) {
tempPath.push(dir);

return dir
? '<a href="/' + tempPath.join('/') + '">' + dir + '</a>'
: '';
}).join(' / ');
}

/**
* Map html `files`, returning an html unordered list.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/public/directory.html
Expand Up @@ -68,7 +68,7 @@
<body class="directory">
<input id="search" type="text" placeholder="Search" autocomplete="off" />
<div id="wrapper">
<h1>{directory}</h1>
<h1>{linked-path}</h1>
{files}
</div>
</body>
Expand Down

0 comments on commit b4898dc

Please sign in to comment.