UNPKG

savant-cli

Version:
71 lines (61 loc) 1.69 kB
#!/usr/bin/env node 'use strict'; var express = require('express') , stylus = require('stylus') , app = express() , _ = require('underscore') , async = require('async'); app.set('views', './pages'); app.set('view engine', 'jade'); app.all('*', function(req, res, next) { res.locals.staticUrl = '/static'; res.locals.staging = true; res.locals.partials = { realm: res.locals.realm }; var queries = []; var templates = { _header: '_header', _footer: '_footer' }; Object.keys(templates).forEach(function(key) { queries.push(function(cb) { res.render(templates[key], res.locals, function(err, html) { if (err) return cb(err); res.locals.partials[key] = html; cb(); }); }); }); async.parallel(queries, next); }); app.get('/*.html', function(req, res, next) { res.render(req.params[0], res.locals, function(err, html) { if (err) return next(err); html = _.template(html, res.locals.partials, { interpolate : /\{\{(.+?)\}\}/g, escape : /\{\{\{(.+?)\}\}\}/g }); res.send(html); }); }); app.use('/static/css', stylus.middleware({ src: './stylesheets', dest: './site/static/css', compile: function(str, path) { return require('stylus')(str) .set('filename', path) .set('compress', true) .set('include css', true) .define('staticUrl', '/static') .use(require('nib')()) .import('nib'); } })); app.use('/static', express.static('./site/static')); app.all('*', function(req, res, next) { res.redirect('http://static.savant.solutions' + req.url) }); app.listen(3000, function() { console.log('Listening on 3000'); });