Comparing version 0.3.0 to 0.3.1
#!/usr/bin/env node | ||
var blake = require('../lib/blake.js') | ||
, resolve = require('path').resolve | ||
@@ -16,6 +15,5 @@ ;(function () { | ||
, target = arg.shift() | ||
, config = require(resolve(source, 'views', 'config.js')) | ||
, files = arg | ||
blake(source, target, config, files, function (err) { | ||
blake(source, target, files, function (err) { | ||
if (err) return console.error(err) | ||
@@ -22,0 +20,0 @@ console.log('OK') |
@@ -1,21 +0,19 @@ | ||
// This module generates the home page. | ||
var jade = require('jade') | ||
, markdown = require('markdown').markdown | ||
var jade = require('jade'); | ||
var markdown = require('markdown').markdown; | ||
exports.bake = function(src, callback) { | ||
var options = { filename:src.templatePath, pretty:true }; | ||
var compile = jade.compile(src.template, options); | ||
exports.bake = function(item, callback) { | ||
var options = { filename:item.templatePath, pretty:true } | ||
, compile = jade.compile(item.template, options) | ||
var locals = { | ||
headline: 'blake', | ||
subline: 'agnostic site bakery', | ||
code: 'https://github.com/michaelnisi/blake', | ||
docs: 'http://michaelnisi.github.com/blake/blake.html', | ||
description: 'blake generates sites', | ||
author: 'Michael Nisi', | ||
content: markdown.toHTML(src.body) | ||
}; | ||
headline: 'blake' | ||
, subline: 'agnostic site bakery' | ||
, code: 'https://github.com/michaelnisi/blake' | ||
, docs: 'http://michaelnisi.github.com/blake/blake.html' | ||
, description: 'blake generates sites' | ||
, author: 'Michael Nisi' | ||
, content: markdown.toHTML(item.body) | ||
} | ||
callback(null, src, compile(locals)); | ||
callback(null, compile(locals)) | ||
} |
@@ -1,12 +0,5 @@ | ||
// This module generates the Blake site. | ||
var blake = require('blake') | ||
var bake = require('blake').bake; | ||
var ok = 'OK'; | ||
console.time(ok); | ||
bake('blake-site', '/tmp/blake-site', function (err) { | ||
if (err) throw(err); | ||
console.timeEnd(ok); | ||
}); | ||
blake('blake-site', '/tmp/blake-site', function (err) { | ||
console.log(err || 'OK') | ||
}) |
@@ -14,8 +14,9 @@ module.exports = blake | ||
, target = args.shift() | ||
, config = args.shift() | ||
, callback = args.pop() | ||
, files = args[0] || null | ||
, config = require(resolve(source, 'config.js')) | ||
, paths = require('./paths.js')(source, target, config) | ||
, templates = require('./templates.js')(paths.templates) | ||
, views = config.bakeFunctions | ||
, views = config.views | ||
, specific = !!args.length && !!args[0].length | ||
, files = specific ? (Array.isArray(args[0]) ? args[0] : args) : null | ||
@@ -27,13 +28,13 @@ var props = { | ||
} | ||
if (files.length) { | ||
return bake(files) | ||
if (specific) { | ||
bake() | ||
} else { | ||
copy(paths.resources, target, function (err) { | ||
bake() | ||
}) | ||
} | ||
copy(paths.resources, target, function (err) { | ||
bake() | ||
}) | ||
function bake (files) { | ||
var reader = getReader(files) | ||
function bake () { | ||
var reader = getReader() | ||
, writer = oven(props) | ||
@@ -52,4 +53,4 @@ | ||
function getReader(files) { | ||
if (files) { | ||
function getReader() { | ||
if (specific) { | ||
var entries = [] | ||
@@ -56,0 +57,0 @@ files.forEach(function (file) { |
@@ -5,12 +5,14 @@ module.exports = templates | ||
, resolve = require('path').resolve | ||
, templates | ||
, me | ||
function templates (path) { | ||
if (templates) return templates | ||
templates = {} | ||
if (me) return me | ||
me = {} | ||
fs.readdirSync(path).forEach(function (name) { | ||
templates[name] = fs.readFileSync(resolve(path, name)) | ||
me[name] = fs.readFileSync(resolve(path, name)) | ||
}) | ||
return templates | ||
return me | ||
} |
@@ -9,3 +9,3 @@ module.exports = write | ||
mkdirp(dirname(path), function (err, made) { | ||
console.log('write %s', path) | ||
console.log('Write %s', path) | ||
writeFile(path, data, callback) | ||
@@ -12,0 +12,0 @@ }) |
{ | ||
"name": "blake", | ||
"description": "generate sites", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"homepage": "http://michaelnisi.github.com/blake/", | ||
@@ -34,4 +34,3 @@ "repository": { | ||
"fstream": ">=0.1.14", | ||
"event-stream": ">=2.1.5", | ||
"through": ">=0.0.3" | ||
"event-stream": ">=2.1.5" | ||
}, | ||
@@ -38,0 +37,0 @@ "devDependencies": { |
@@ -12,3 +12,3 @@ # blake - generate sites | ||
Blake is a [Node.js](http://nodejs.org) module that provides a simple, blog aware, and view agnostic infrastructure to generate static websites. For unrestricted choice of input formats and template languages, blake confines itself to IO and template routing; it delegates the actual file generation to user-written view modules. Blake runs asynchronously; it can be used from command-line or as library. | ||
Blake is a [Node.js](http://nodejs.org) module that provides a simple, blog aware, and view agnostic infrastructure to generate static websites. For unrestricted choice of input formats and template languages, blake confines itself to IO and template routing; it delegates the actual file generation to user-written generator functions. Blake is non-blocking; it can be used from command-line or as library. | ||
@@ -49,30 +49,26 @@ [![Build Status](https://secure.travis-ci.org/michaelnisi/blake.png)](http://travis-ci.org/michaelnisi/blake) | ||
At startup blake requires a configuration module, which has to export paths and a map of user-written functions that implement the actual generation of output artifacts. According to the configuration module blake reads all input data files. At the top of each input file blake expects a JSON header. From the header and the content of the input file blake constructs a source object, with which it applies the `bake` function of the according view module. This is done for all input files in parallel. The static resources are copied to the output directory as they are. | ||
Blake requires a configuration module (config.js), which it expects to load from the root of the source directory; config has to export a paths object, and a map of generator functions. If no files are explicitly specifified, blake copies the static resoures to the target directory, and each data source is piped to a stream that generates and writes the arfifact to the target directory. | ||
## CONFIGURATION | ||
Consider the following example of a configuration module: | ||
Consider the following configuration module: | ||
// This module covers configuration. | ||
// Export path conventions for input data. | ||
exports.paths = { | ||
data: 'data', // required | ||
templates: 'templates', // required | ||
resources: 'resources', // optional | ||
posts: 'data/posts' // optional | ||
}; | ||
data: 'data' // required | ||
, templates: 'templates' // required | ||
, resources: 'resources' // optional | ||
, posts: 'data/posts' // optional | ||
} | ||
// Export map with bake functions by template names. | ||
exports.bakeFunctions = { | ||
'rss.jade': require('./rss.js').bake, | ||
'article.jade': require('./article.js').bake, | ||
'home.jade': require('./home.js').bake, | ||
'about.jade': require('./about.js').bake, | ||
'archive.jade': require('./archive.js').bake | ||
}; | ||
exports.views = { | ||
'rss.jade': require('./rss.js').bake | ||
, 'article.jade': require('./article.js').bake | ||
, 'home.jade': require('./home.js').bake | ||
, 'about.jade': require('./about.js').bake | ||
, 'archive.jade': require('./archive.js').bake | ||
} | ||
The `paths` object defines input paths, where the two required directories are `data` and `templates`. From `data` blake loads general input data; from `templates` templates. The two optional directories are `resources` and `posts`. The content of `resources` is copied to output as it is. The `posts` directory hosts blog posts. | ||
The `bakeFunctions` object is a map of user-written functions which implement the actual generation of output artifacts. Theses functions are mapped by template name. | ||
The `views` object is a map of user-written functions which implement the actual generation of output artifacts. Theses functions are mapped by template name. | ||
@@ -139,3 +135,3 @@ ## INPUT | ||
bake (src, callback) | ||
bake (item, callback) | ||
@@ -146,23 +142,25 @@ In this function you implement the transformation from input to output and pass the result to the callback. | ||
header: { title: 'Closure', | ||
description: 'A function together with a referencing environment', | ||
template: 'article.jade', | ||
date: Tue, 18 Oct 2011 00:00:00 GMT, | ||
name: 'closures.html', | ||
path: '/2011/10' }, | ||
body: '…', | ||
paths: { outputPathName: '../website', | ||
pathToResources: 'resources', | ||
pathToData: 'data', | ||
templatesPathName: 'templates', | ||
posts: 'data/posts', | ||
config: 'views/config.js' }, | ||
filename: 'data/posts/2011/10/closures.md', | ||
date: Tue, 18 Oct 2011 00:00:00 GMT, | ||
templatePath: 'templates/article.jade', | ||
path: '../website/2011/10', | ||
name: 'closures.html', | ||
link: '/2011/10/closures', | ||
dateString: 'Tue Oct 18 2011', | ||
template: '…' | ||
{ header: | ||
{ title: 'Static Websites', | ||
description: '...', | ||
template: 'article.jade', | ||
data: Thu May 17 2012 02:00:00 GMT +0200 (CEST), | ||
path: '2012/05', | ||
name: 'static-websites.html' } | ||
body: '...', | ||
paths: | ||
{ target: '/tmp/michaelnisi-site', | ||
resources: '/Users/michael/workspace/michaelnisi/resources', | ||
data: '/Users/michael/workspace/michaelnisi/data', | ||
templates: '/Users/michael/workspace/michaelnisi/templates', | ||
posts: '/Users/michael/workspace/michaelnisi/data/posts' }, | ||
title: 'Static Websites', | ||
name: 'static-websites.html', | ||
date: Thu May 17 2012 02:00:00 GMT+0200 (CEST), | ||
templatePath: '/Users/michael/workspace/michaelnisi/templates/article.jade', | ||
path: '/tmp/michaelnisi-site/2012/05/static-websites.html', | ||
link: '2012/05/static-websites', | ||
dateString: 'Thu May 17 2012', | ||
bake: [Function], | ||
template: <Buffer 0a 20 20 20 20 64 69 76 ...> } | ||
@@ -181,5 +179,4 @@ To see a simple example: | ||
blake michaelnisi /tmp/michaelnisi-site | ||
node /tmp/michaelnisi-site/conf/dev.js | ||
You might want to read the [documentation](http://michaelnisi.github.com/michaelnisi/article.html) of the views for this site, which are written in [CoffeeScript](http://coffeescript.org/); not to put you off, just to give it a shot—I found the use case rather fitting. | ||
## DEPLOYMENT | ||
@@ -186,0 +183,0 @@ |
@@ -24,9 +24,1 @@ var test = require('tap').test | ||
test('ENOENT', function (t) { | ||
var fn = function () { | ||
copy('xxx', target) | ||
} | ||
t.doesNotThrow(fn) | ||
t.end() | ||
}) |
@@ -5,2 +5,4 @@ var test = require('tap').test | ||
, props = require('./props.js') | ||
, paths = props().paths | ||
, target = paths.target | ||
@@ -23,3 +25,3 @@ test('read', function (t) { | ||
t.ok(item.body, 'should have a body') | ||
t.equal(item.path, 'target/about.html', 'should be correct path') | ||
t.equal(item.path, target + '/about.html', 'should be correct path') | ||
t.equal(item.title, header.title, 'should be header title') | ||
@@ -30,1 +32,13 @@ | ||
test('article', function (t) { | ||
var filename = 'source/data/posts/2012/double-negative.md' | ||
, file = readFileSync(filename) | ||
, item = getItem(props(), filename, file.toString()) | ||
, link = '2012/05/double-negative' | ||
, path = target + '/2012/05/double-negative.html' | ||
t.equal(item.link, link, 'should be correct link') | ||
t.equal(item.path, path, 'should be correct path') | ||
t.end() | ||
}) |
module.exports = props | ||
var resolve = require('path').resolve | ||
, me | ||
function props () { | ||
if (me) return me | ||
var source = 'source' | ||
, target = 'target' | ||
, target = '/tmp/blake-test' | ||
, config = require(resolve(source, 'config.js')) | ||
@@ -13,3 +16,3 @@ , paths = require('../lib/paths')(source, target, config) | ||
var props = { | ||
var me = { | ||
paths: paths | ||
@@ -20,4 +23,4 @@ , views: views | ||
return props | ||
return me | ||
} | ||
@@ -9,2 +9,6 @@ exports.paths = { | ||
exports.views = { | ||
'about.jade': function (item, cb) { cb() } | ||
} | ||
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
125237
3
41
731
0
205
14
- Removedthrough@>=0.0.3