Skip to content
Browse files

continuing

  • Loading branch information...
1 parent 12865c7 commit c757cbb939040aa5481c7c0d9cbd15427b90efed @Bonuspunkt Bonuspunkt committed
Showing with 107 additions and 16 deletions.
  1. +40 −1 README.md
  2. +6 −8 bin/cli.js
  3. +4 −0 index.js
  4. +4 −4 lib/handler.js
  5. +25 −0 lib/init.js
  6. +2 −2 lib/processFile.js
  7. +1 −1 lib/simpleMustache.js
  8. +25 −0 package.json
View
41 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
View
14 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) {
View
4 index.js
@@ -0,0 +1,4 @@
+module.exports = {
+ init: require('./lib/init'),
+ handler: require('./lib/handler')
+};
View
8 lib/handler.js
@@ -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'];
@@ -68,6 +68,6 @@ module.exports = function(wwwRoot) {
};
checkDone();
});
- })
- }
-}
+ });
+ };
+};
View
25 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);
+ });
+};
View
4 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) {
@@ -62,4 +62,4 @@ module.exports = function(wwwRoot) {
}
serveFile(file, ext, res);
};
-}
+};
View
2 lib/simpleMustache.js
@@ -3,4 +3,4 @@ module.exports = function(template, data) {
match = match.substring(2, match.length - 2);
return data[match];
});
-}
+};
View
25 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.
Something went wrong with that request. Please try again.