Comparing version 0.5.0 to 0.6.0
// blake - generate site | ||
module.exports = blake | ||
var generate = require('./lib/generate.js') | ||
, join = require('path').join | ||
function blake (source, target) { | ||
module.exports = function (source, target) { | ||
var config = require(join(source, 'config.js')) | ||
@@ -10,0 +8,0 @@ , paths = require('./lib/paths.js')(source, target, config) |
// copy - copy source directory and its subtree to target directory | ||
module.exports = copy | ||
var fstream = require('fstream') | ||
, resolve = require('path').resolve | ||
function copy (source, target, callback) { | ||
module.exports = function (source, target, callback) { | ||
var reader = fstream.Reader({ path: source }) | ||
, writer = fstream.Writer({ path: target, type: 'Directory' }) | ||
reader.pipe(writer) | ||
reader.on('error', function (err) { | ||
@@ -22,3 +18,3 @@ writer.emit('error', err) | ||
return writer | ||
return reader.pipe(writer) | ||
} |
// generate - generate and write artifacts | ||
module.exports = generate | ||
var Stream = require('stream').Stream | ||
@@ -10,3 +8,3 @@ , fs = require('fs') | ||
function generate (props) { | ||
module.exports = function (props) { | ||
var stream = new Stream() | ||
@@ -13,0 +11,0 @@ , read = reader(props).read |
// getItem - create and return source item | ||
module.exports = getItem | ||
var path = require('path') | ||
, strftime = require('prettydate').strftime | ||
, END_MARKER = '\n\n' | ||
@@ -16,3 +15,3 @@ , HTML = 'html' | ||
function getItem (props, filename, str) { | ||
module.exports = function (props, filename, str) { | ||
var item = Object.create(null) | ||
@@ -52,6 +51,7 @@ , tokens = str.split(END_MARKER) | ||
item.date = header.date | ||
item.pubDate = strftime(header.date, '%a, %d %b %Y %T %z') | ||
item.dateString = header.date.toDateString() | ||
item.templatePath = path.join(paths.templates, header.template) | ||
item.path = path.join(paths.target, header.path, header.name) | ||
item.link = path.join(header.path, header.name) | ||
item.dateString = header.date.toDateString() | ||
item.bake = views[header.template] | ||
@@ -58,0 +58,0 @@ item.template = templates[header.template] |
// getReader - return stream of filenames | ||
module.exports = getReader | ||
var Reader = require('fstream').Reader | ||
@@ -9,3 +7,3 @@ , resolve = require('path').resolve | ||
function getReader (source, filenames) { | ||
module.exports = function (source, filenames) { | ||
var reader | ||
@@ -12,0 +10,0 @@ |
// paths - default paths | ||
module.exports = paths | ||
var join = require('path').join | ||
, me | ||
function paths (source, target, config) { | ||
module.exports = function (source, target, config) { | ||
if (me) return me | ||
@@ -10,0 +8,0 @@ |
// read - read files and return blake items | ||
module.exports = reader | ||
var getItem = require('./getItem.js') | ||
@@ -9,9 +7,11 @@ , fs = require('fs') | ||
, Stream = require('stream').Stream | ||
, hash = require('./hash.js') | ||
, cache = require('./cache.js') | ||
, me | ||
function reader (props) { | ||
module.exports = function (props) { | ||
if (me) return me | ||
me = {} | ||
me.read = function (path, callback) { | ||
@@ -27,10 +27,9 @@ fs.stat(path, function (err, stats) { | ||
me.clearCache = function () { | ||
me.cache = Object.create(null) | ||
return me | ||
} | ||
function readFile (filename, callback) { | ||
var key = hash(filename) | ||
, cached = cache.get(key) | ||
function readFile (filename, callback) { | ||
if (me.cache) { | ||
// TODO Cache? | ||
if (cached) { | ||
callback(null, cached) | ||
return | ||
} | ||
@@ -40,2 +39,3 @@ | ||
var item = getItem(props, filename, data.toString()) | ||
cache.set(key, item) | ||
return callback(err, item) | ||
@@ -54,3 +54,3 @@ }) | ||
stream.add = function (entry) { | ||
if (entry.type !== 'File') { | ||
if (entry.type === 'Directory') { | ||
entry.on('entry', stream.add) | ||
@@ -61,3 +61,8 @@ return true | ||
readFile(entry.path, function (err, item) { | ||
items.push(item) | ||
var seen = items.some(function (it) { | ||
return it.path === item.path | ||
}) | ||
// not sure why we get repeats here | ||
if (!seen) items.push(item) | ||
reader.resume() | ||
@@ -75,3 +80,3 @@ }) | ||
return props.withCache ? me.clearCache() : me | ||
return me | ||
} | ||
@@ -78,0 +83,0 @@ |
// templates - cache templates | ||
module.exports = templates | ||
var fs = require('fs') | ||
@@ -9,3 +7,3 @@ , resolve = require('path').resolve | ||
function templates (path) { | ||
module.exports = function (path) { | ||
if (me) return me | ||
@@ -12,0 +10,0 @@ |
// write - write file and create intermediate directories as required | ||
module.exports = write | ||
var mkdirp = require('mkdirp') | ||
@@ -9,3 +7,3 @@ , dirname = require('path').dirname | ||
function write (path, data, callback) { | ||
module.exports = function (path, data, callback) { | ||
mkdirp(dirname(path), function (err, made) { | ||
@@ -15,2 +13,1 @@ writeFile(path, data, callback) | ||
} | ||
{ | ||
"name": "blake", | ||
"description": "Simple, blog aware infrastructure to generate static sites", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"homepage": "http://michaelnisi.github.com/blake/", | ||
@@ -31,3 +31,4 @@ "repository": { | ||
"mkdirp": "", | ||
"fstream": "", | ||
"fstream": "", | ||
"lru-cache": "", | ||
"event-stream": "", | ||
@@ -34,0 +35,0 @@ "cop": "", |
@@ -18,3 +18,3 @@ # blake - generate site | ||
Generate from directory: | ||
### Generate from directory | ||
@@ -35,3 +35,3 @@ var blake = require('blake') | ||
Copy static resources and generate from directory: | ||
### Copy static resources and generate from directory | ||
@@ -59,3 +59,3 @@ var blake = require('blake') | ||
Generate from files: | ||
### Generate from files | ||
@@ -65,3 +65,3 @@ var blake = require('blake') | ||
, readArray = require('event-stream').readArray | ||
, filenames = ['first/fil', 'second/file', 'third/file'] | ||
, filenames = ['first/file', 'second/file', 'third/file'] | ||
, source = 'source_directory' | ||
@@ -75,5 +75,34 @@ , target = 'target_directory' | ||
### Generate and push to S3 | ||
Since blake returns a Stream that emits the paths of the generated artifacts, we can pipe to [pushup](https://github.com/michaelnisi/pushup), and upload the files directly to S3. | ||
var resolve = require('path').resolve | ||
, cop = require('cop') | ||
, getProps = require('pushup/lib/getProps') | ||
, blake = require('blake') | ||
, pushup = require('pushup') | ||
, Reader = require('fstream').Reader | ||
, sep = require('path').sep | ||
, source = 'source_directory' | ||
, target = '/tmp/target_directory' | ||
, reader = new Reader({ path:resolve(source, 'data') }) | ||
, props = getProps() | ||
process.chdir(target) | ||
reader | ||
.pipe(cop('path')) | ||
.pipe(blake(source, target)) | ||
.pipe(cop(adjustPath)) | ||
.pipe(pushup(props)) | ||
.pipe(process.stdout) | ||
function adjustPath (p) { | ||
return p.split(sep).slice(3).join(sep) | ||
} | ||
## Events | ||
The `blake` function returns a readable and writable [Stream](http://nodejs.org/api/stream.html) that emits following events: | ||
The blake function returns a readable and writable [Stream](http://nodejs.org/api/stream.html) that emits following events: | ||
@@ -100,3 +129,3 @@ ### Event: 'data' | ||
blake requires a configuration module (`source_directory/config.js´), which exports `paths`, and `views`, a map of generator functions: | ||
blake requires a configuration module at `source_directory/config.js`, which exports `paths`, and `views`, a map of generator functions: | ||
@@ -103,0 +132,0 @@ exports.paths = { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38682
40
575
270
6
7
+ Addedlru-cache@
+ Addedlru-cache@11.0.2(transitive)