Skip to content

Commit

Permalink
continuing
Browse files Browse the repository at this point in the history
  • Loading branch information
Bonuspunkt committed Sep 18, 2012
1 parent 12865c7 commit c757cbb
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 16 deletions.
41 changes: 40 additions & 1 deletion README.md
@@ -1 +1,40 @@
# mdserv
# mdserv
static http server with markdown support

##installation
npm install mdserv

if you want to use it from the cli install it with

npm install mdserv -g

## usage

### cli

mdserv init [directory]

copies the .template.html to the directory. `directory` default to the current
directory. the directory needs to exist, if the template exists, it will be
overridden.

mdserv serve [directory] [port]

starts a http server, that serves files from the directory.
`directory` defaults to the current directory, `port` defaults to 3340

### module
var mdserv = require('mdserv');

mdserve.init(dir, [callback])

var handler = mdserve.handler(wwwRoot);
http.createServer(handler).listen(3340);


## customizing
you can edit the `.template.html` and all not `.md` `.markdown` will be served
like from a static webserver.

##license
public domain
14 changes: 6 additions & 8 deletions bin/cli.js
@@ -1,28 +1,26 @@
#!/usr/bin/env node
var http = require('http');
var path = require('path');

var init = require('../lib/init');
var handler = require('../lib/handler');

function usage() {
console.log('mdserv init <directory>');
console.log('mdserv serve <directory> <port>');
console.log('mdserv init [directory]');
console.log('mdserv serve [directory] [port]');
}

function serve(directory, port) {

directory = path.resolve(directory || '.');
directory = path.resolve(directory);

var handlerInstance = handler(directory);
http.createServer(handlerInstance).listen(port || 0xD0C);
}

function init(directory) {
}

var args = process.argv.slice(2);

var command = (args[0] || '').toLowerCase();
var directory = args[1];
var directory = args[1] || '.';
var port = Number(args[2]);

switch (command) {
Expand Down
4 changes: 4 additions & 0 deletions index.js
@@ -0,0 +1,4 @@
module.exports = {
init: require('./lib/init'),
handler: require('./lib/handler')
};
8 changes: 4 additions & 4 deletions lib/handler.js
Expand Up @@ -2,7 +2,7 @@ var fs = require('fs');
var path = require('path');

var processDirectory = require('./processDirectory');
var processFile = require('./processFile')
var processFile = require('./processFile');

var suffixes = ['/index.md', '/index.markdown', '', '.md', '.markdown'];

Expand Down Expand Up @@ -68,6 +68,6 @@ module.exports = function(wwwRoot) {
};
checkDone();
});
})
}
}
});
};
};
25 changes: 25 additions & 0 deletions lib/init.js
@@ -0,0 +1,25 @@
var fs = require('fs');
var path = require('path');

module.exports = function(directory, cb) {

var callback = function() {
if (cb) {
cb = null;
cb.apply(null, arguments);
}
};

var templateName = '.template.html';
var source = path.resolve(__dirname, '../template', templateName);
var target = path.resolve(directory, templateName);

fs.exists(target, function(exist) {
var sourceStream = fs.createReadStream(source);
var targetStream = fs.createWriteStream(target);
targetStream.on('error', callback);

sourceStream.pipe(targetStream);
sourceStream.on('end', callback);
});
};
4 changes: 2 additions & 2 deletions lib/processFile.js
@@ -1,7 +1,7 @@
var fs = require('fs');
var path = require('path');
var mime = require('mime');
var marked = require('marked')
var marked = require('marked');
var simpleMustache = require('./simpleMustache');

module.exports = function(wwwRoot) {
Expand Down Expand Up @@ -62,4 +62,4 @@ module.exports = function(wwwRoot) {
}
serveFile(file, ext, res);
};
}
};
2 changes: 1 addition & 1 deletion lib/simpleMustache.js
Expand Up @@ -3,4 +3,4 @@ module.exports = function(template, data) {
match = match.substring(2, match.length - 2);
return data[match];
});
}
};
25 changes: 25 additions & 0 deletions package.json
@@ -0,0 +1,25 @@
{
"name": "mdserv",
"version": "0.0.0",
"description": "static http server with markdown support",
"main": "index.js",
"bin": {
"mdserv": "cli.js"
},
"dependencies": {
"mime": "~1.2.7",
"marked": "~0.2.5"
},
"devDependencies": {},
"scripts": {
"test": "node test/test.js"
},
"repository": "",
"keywords": [
"http",
"server",
"markdown"
],
"author": "Bonuspunkt",
"license": "public domain"
}

0 comments on commit c757cbb

Please sign in to comment.