metalsmith
Advanced tools
Comparing version 1.3.0 to 1.4.0
1.3.0 / 2015-02-06 | ||
================== | ||
1.4.0 - March 25, 2015 | ||
---------------------- | ||
* add support for overriding the read and write directory | ||
* adding support for local (non-npm, but still node) plugins | ||
1.3.0 - February 6, 2015 | ||
------------------------ | ||
* adding support for local (non-npm, but still node) plugins | ||
@@ -7,0 +10,0 @@ 1.2.0 - February 4, 2015 |
@@ -16,2 +16,6 @@ | ||
var isAbsolute = path.isAbsolute; | ||
var relative = path.relative; | ||
var resolve = path.resolve; | ||
/** | ||
@@ -68,3 +72,3 @@ * Thunks. | ||
Metalsmith.prototype.directory = function(directory){ | ||
if (!arguments.length) return path.resolve(this._directory); | ||
if (!arguments.length) return resolve(this._directory); | ||
assert(is.string(directory), 'You must pass a directory path string.'); | ||
@@ -154,7 +158,7 @@ this._directory = directory; | ||
paths.unshift(this.directory()); | ||
return path.resolve.apply(path, paths); | ||
return resolve.apply(path, paths); | ||
}; | ||
/** | ||
* Build with the current settings to the dest directory. | ||
* Build with the current settings to the destination directory. | ||
* | ||
@@ -189,15 +193,17 @@ * @return {Object} | ||
/** | ||
* Read the source directory, parsing front matter and call `fn(files)`. | ||
* Read a dictionary of files from a `dir`, parsing frontmatter. If no directory | ||
* is provided, it will default to the source directory. | ||
* | ||
* @param {String} dir (optional) | ||
* @return {Object} | ||
*/ | ||
Metalsmith.prototype.read = unyield(function*(){ | ||
var src = this.source(); | ||
Metalsmith.prototype.read = unyield(function*(dir){ | ||
dir = dir || this.source(); | ||
var read = this.readFile.bind(this); | ||
var paths = yield readdir(src); | ||
var paths = yield readdir(dir); | ||
var files = yield paths.map(read); | ||
return paths.reduce(function(memo, file, i){ | ||
file = path.relative(src, file); | ||
file = relative(dir, file); | ||
memo[file] = files[i]; | ||
@@ -209,3 +215,4 @@ return memo; | ||
/** | ||
* Read a single file by file `path`. | ||
* Read a file by `path`. If the path is not absolute, it will be resolved | ||
* relative to the source directory. | ||
* | ||
@@ -217,2 +224,5 @@ * @param {String} path | ||
Metalsmith.prototype.readFile = unyield(function*(path){ | ||
var src = this.source(); | ||
if (!isAbsolute(path)) path = resolve(src, path); | ||
try { | ||
@@ -242,11 +252,16 @@ var frontmatter = this.frontmatter(); | ||
/** | ||
* Write a dictionary of `files` to the dest directory. | ||
* Write a dictionary of `files` to a destination `dir`. If no directory is | ||
* provided, it will default to the destination directory. | ||
* | ||
* @param {Object} files | ||
* @param {String} dir (optional) | ||
*/ | ||
Metalsmith.prototype.write = unyield(function*(files){ | ||
Metalsmith.prototype.write = unyield(function*(files, dir){ | ||
dir = dir || this.destination(); | ||
var write = this.writeFile.bind(this); | ||
yield Object.keys(files).map(function(file){ | ||
return write(file, files[file]); | ||
var path = resolve(dir, file); | ||
return write(path, files[file]); | ||
}); | ||
@@ -256,14 +271,16 @@ }); | ||
/** | ||
* Write a `file` with `data` to the destination directory. | ||
* Write a file by `path` with `data`. If the path is not absolute, it will be | ||
* resolved relative to the destination directory. | ||
* | ||
* @param {String} file | ||
* @param {String} path | ||
* @param {Object} data | ||
*/ | ||
Metalsmith.prototype.writeFile = unyield(function*(file, data){ | ||
Metalsmith.prototype.writeFile = unyield(function*(path, data){ | ||
var dest = this.destination(); | ||
if (!isAbsolute(path)) path = resolve(dest, path); | ||
try { | ||
var dest = this.destination(); | ||
var out = path.resolve(dest, file); | ||
yield fs.outputFile(out, data.contents); | ||
if (data.mode) yield fs.chmod(out, data.mode); | ||
yield fs.outputFile(path, data.contents); | ||
if (data.mode) yield fs.chmod(path, data.mode); | ||
} catch (e) { | ||
@@ -270,0 +287,0 @@ e.message = 'Failed to write the file at: ' + file + '\n\n' + e.message; |
{ | ||
"name": "metalsmith", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "git://github.com/segmentio/metalsmith.git", |
@@ -129,3 +129,14 @@ | ||
If you want to use a custom plugin, but feel like it's too domain-specific to | ||
be published to the world, you can include plugins as local npm modules: | ||
(simply use a relative path from your root directory) | ||
```json | ||
{ | ||
"plugins": { | ||
"./lib/metalsmith/plugin.js": true | ||
} | ||
} | ||
``` | ||
## API | ||
@@ -132,0 +143,0 @@ |
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
21943
248
226
0