Compare commits

...

5 Commits

Author SHA1 Message Date
Douglas Christopher Wilson
9fbc4bf182 1.0.3 2014-05-20 10:23:05 -04:00
Douglas Christopher Wilson
027f6dcf54 Fix error from non-statable files in HTML view
fixes #6
2014-05-20 10:14:31 -04:00
Douglas Christopher Wilson
f7eb0ae92a docs: add History 2014-05-20 10:00:15 -04:00
Fishrock123
51e9763c0a docs: enhance 2014-04-29 10:53:47 -04:00
Chris O'Connor
dd6a4a864a docs: fix typo, add stylesheet
closes #4
2014-04-29 10:37:11 -04:00
4 changed files with 65 additions and 32 deletions

20
History.md Normal file
View File

@@ -0,0 +1,20 @@
1.0.3 / 2014-05-20
==================
* Fix error from non-statable files in HTML view
1.0.2 / 2014-04-28
==================
* Add `stylesheet` option
* deps: negotiator@0.4.3
1.0.1 / 2014-03-05
==================
* deps: negotiator@0.4.2
1.0.0 / 2014-03-05
==================
* Genesis from connect

View File

@@ -1,21 +1,37 @@
# Serve Index
# serve-index [![Build Status](https://travis-ci.org/expressjs/serve-index.svg?branch=master)](https://travis-ci.org/expressjs/serve-index) [![NPM version](https://badge.fury.io/js/serve-index.svg)](http://badge.fury.io/js/serve-index)
Previously `connect.directory()`.
Serves pages that contain directory listings for a given path.
[![Build Status](https://travis-ci.org/expressjs/serve-index.svg?branch=master)](https://travis-ci.org/expressjs/serve-index)
Usage:
## API
```js
var connect = require('connect');
var serveIndex = require('serve-index');
var express = require('express')
var directory = require('serve-index')
var app = connect();
var app = express()
app.use(serveIndex('public/ftp', {'icons': true}));
app.listen();
app.use(directory('public/ftp', {'icons': true}))
app.listen()
```
### directory(path, options)
Returns middlware that serves an index of the directory in the given `path`.
#### Options
- `hidden` - display hidden (dot) files. Defaults to `false`.
- `view` - display mode. `tiles` and `details` are available. Defaults to `tiles`.
- `icons` - display icons. Defaults to `false`.
- `filter` - Apply this filter function to files. Defaults to `false`.
- `stylesheet` - Optional path to a CSS stylesheet. Defaults to a built-in stylesheet.
- `template` - Optional path to an HTML template. Defaults to a built-in template.
- The following tokens are replaced in templates:
- `{directory}` with the name of the directory.
- `{files}` with the HTML of an unordered list of file links.
- `{linked-path}` with the HTML of a link to the directory.
- `{style}` with the specified stylesheet and embedded images.
## License
The MIT License (MIT)

View File

@@ -1,6 +1,6 @@
/*!
* Connect - directory
* Expressjs | Connect - directory
* Copyright(c) 2011 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
* Copyright(c) 2014 Douglas Christopher Wilson
@@ -60,26 +60,13 @@ var mediaType = {
};
/**
* Directory:
*
* Serve directory listings with the given `root` path.
*
* Options:
* See Readme.md for documentation of options.
*
* - `hidden` display hidden (dot) files. Defaults to false.
* - `view` display mode. 'titles' and 'details' are available. Defaults to titles.
* - `icons` display icons. Defaults to false.
* - `filter` Apply this filter function to files. Defaults to false.
* - `template` Optional path to html template. Defaults to a built-in template.
* The following tokens are replaced:
* - `{directory}` with the name of the directory.
* - `{files}` with the HTML of an unordered list of file links.
* - `{linked-path}` with the HTML of a link to the directory.
* - `{style}` with the built-in CSS and embedded images.
*
* @param {String} root
* @param {String} path
* @param {Object} options
* @return {Function}
* @return {Function} middleware
* @api public
*/
@@ -294,9 +281,12 @@ function html(files, dir, useIcons, view) {
path.push(encodeURIComponent(file.name));
var date = file.name == '..' ? ''
: file.stat.mtime.toDateString()+' '+file.stat.mtime.toLocaleTimeString();
var size = isDir ? '' : file.stat.size;
var date = file.stat && file.name !== '..'
? file.stat.mtime.toDateString() + ' ' + file.stat.mtime.toLocaleTimeString()
: '';
var size = file.stat && !isDir
? file.stat.size
: '';
return '<li><a href="'
+ normalizeSlashes(normalize(path.join('/')))
@@ -364,7 +354,14 @@ function stat(dir, files, cb) {
files.forEach(function(file){
batch.push(function(done){
fs.stat(join(dir, file), done);
fs.stat(join(dir, file), function(err, stat){
if (err && err.code !== 'ENOENT') {
// pass ENOENT as null stat, not error
return done(err);
}
done(null, stat || null);
});
});
});

View File

@@ -1,7 +1,7 @@
{
"name": "serve-index",
"description": "Serve directory listings",
"version": "1.0.2",
"version": "1.0.3",
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
"license": "MIT",
"repository": {