metalsmith
Advanced tools
Comparing version 0.1.0 to 0.2.2
0.2.1 - March 7, 2013 | ||
--------------------- | ||
* change to `chalk` from `colors` | ||
0.2.0 - March 6, 2013 | ||
--------------------- | ||
* change to `#metadata` just being a getter | ||
0.1.0 - February 5, 2013 | ||
------------------------ | ||
* switch to `contents` always being a Buffer | ||
* change to `contents` always being a Buffer | ||
@@ -6,0 +14,0 @@ 0.0.4 - February 5, 2013 |
@@ -28,2 +28,3 @@ | ||
this.ware = new Ware(); | ||
this.data = {}; | ||
this.source('src'); | ||
@@ -46,2 +47,13 @@ this.destination('build'); | ||
/** | ||
* Get the global `metadata` to pass to templates. | ||
* | ||
* @param {Object} metadata | ||
* @return {Object or Metalsmith} | ||
*/ | ||
Metalsmith.prototype.metadata = function(metadata){ | ||
return this.data; | ||
}; | ||
/** | ||
* Get or set the source directory. | ||
@@ -73,15 +85,2 @@ * | ||
/** | ||
* Get or set global `metadata` to pass to templates. | ||
* | ||
* @param {Object} metadata | ||
* @return {Object or Metalsmith} | ||
*/ | ||
Metalsmith.prototype.metadata = function(metadata){ | ||
if (!arguments.length) return this._data || {}; | ||
this._data = metadata; | ||
return this; | ||
}; | ||
/** | ||
* Join path `strs` with the working directory. | ||
@@ -130,5 +129,5 @@ * | ||
var files = {}; | ||
var dir = this.source(); | ||
var src = this.source(); | ||
readdir(dir, function(err, arr){ | ||
readdir(src, function(err, arr){ | ||
if (err) return fn(err); | ||
@@ -141,3 +140,3 @@ each(arr, read, function(err){ | ||
function read(file, done){ | ||
var name = path.relative(dir, file); | ||
var name = path.relative(src, file); | ||
fs.readFile(file, function(err, buffer){ | ||
@@ -144,0 +143,0 @@ if (err) return done(err); |
{ | ||
"name": "metalsmith", | ||
"repository": "git://github.com/segmentio/metalsmith.git", | ||
"version": "0.1.0", | ||
"version": "0.2.2", | ||
"license": "MIT", | ||
@@ -33,3 +33,4 @@ "description": "An extremely simple, pluggable static site generator.", | ||
"defaults": "~1.0.0", | ||
"is-utf8": "~0.2.0" | ||
"is-utf8": "~0.2.0", | ||
"chalk": "^0.4.0" | ||
}, | ||
@@ -40,6 +41,4 @@ "devDependencies": { | ||
"fs-readdir-recursive": "0.0.1", | ||
"swig": "~1.3.2", | ||
"assert-dir-equal": "~0.1.0", | ||
"metalsmith-drafts": "0.0.1" | ||
"assert-dir-equal": "~0.1.0" | ||
} | ||
} | ||
} |
137
Readme.md
@@ -0,6 +1,27 @@ | ||
# Metalsmith | ||
# metalsmith | ||
An extremely simple, _pluggable_ static site generator. | ||
An extremely simple, _pluggable_ static site generator. | ||
In Metalsmith, all of the logic is handled by plugins. You simply chain them together. Here's what the simplest blog looks like... | ||
```js | ||
Metalsmith(__dirname) | ||
.use(markdown) | ||
.use(templates('handlebars')) | ||
.build(); | ||
``` | ||
...but what if you want to get fancier by hiding your unfinished drafts and using custom permalinks? Just add plugins... | ||
```js | ||
Metalsmith(__dirname) | ||
.use(drafts) | ||
.use(markdown) | ||
.use(permalinks('posts/:title')) | ||
.use(templates('handlebars')) | ||
.build(); | ||
``` | ||
...it's as easy as that! | ||
## Installation | ||
@@ -10,65 +31,115 @@ | ||
## Example | ||
## Plugins | ||
With a directory structure like this ... | ||
Check out the website for a list of [plugins](http://www.metalsmith.io#the-plugins). | ||
/blog | ||
/src | ||
/a-post.md | ||
/another-post.md | ||
## How does it work? | ||
... running Metalsmith ... | ||
Metalsmith works in three simple steps: | ||
$ metalsmith | ||
1. Read all the files in a source directory. | ||
2. Invoke a series of plugins that manipulate the files. | ||
3. Write the results to a destination directory! | ||
... will create: | ||
Each plugin is invoked with the contents of the source directory, and each file can contain YAML front-matter that will be attached as metadata, so a simple file like... | ||
/blog | ||
/build | ||
/a-post.html | ||
/another-post.html | ||
--- | ||
title: A Catchy Title | ||
date: 2014-12-01 | ||
--- | ||
An informative article. | ||
...would be parsed into... | ||
```js | ||
{ | ||
'path/to/my-file.md': { | ||
title: 'A Catchy Title', | ||
date: new Date('2014-12-01'), | ||
contents: new Buffer('An informative article.') | ||
} | ||
} | ||
``` | ||
...which any of the plugins can then manipulate however they want. And writing the plugins is incredibly simple, just take a look at the [example drafts plugin](examples/drafts-plugin/index.js). | ||
Of course they can get a lot more complicated too. That's what makes Metalsmith powerful; the plugins can do anything you want! | ||
## The secret... | ||
We keep referring to Metalsmith as a "static site generator", but it's a lot more than that. Since everything is a plugin, the core library is actually just an abstraction for manipulating a directory of files. | ||
Which means you could just as easily use it to make... | ||
- [A simple project scaffolder.](examples/project-scaffolder) | ||
- [A simple build tool for Sass files.](examples/build-tool) | ||
- [A simple static site generator.](examples/static-site) | ||
- [An Jekyll-like static site generator.](examples/jekyll) | ||
- [An Wintersmith-like static site generator.](examples/wintersmith) | ||
## CLI | ||
Usage: metalsmith [options] | ||
Options: | ||
In addition to a simple [Javascript API](#api), the Metalsmith CLI can read configuration from a `metalsmith.json` file, so that you can build static-site generators similar to [Jekyll](jekyllrb.com) or [Wintersmith](wintersmith.io) easily. The example blog above would be configured like this: | ||
```json | ||
{ | ||
"source": "src", | ||
"destination": "build", | ||
"plugins": { | ||
"metalsmith-drafts": true, | ||
"metalsmith-markdown": true, | ||
"metalsmith-permalinks": "posts/:title", | ||
"metalsmith-templates": "handlebars" | ||
} | ||
} | ||
``` | ||
And then from the CLI, simply run... | ||
$ metalsmith | ||
-h, --help output usage information | ||
-c, --config set a config file | ||
-d, --destination set the destination directory | ||
-s, --source set the source directory | ||
Metalsmith · reading configuration from: /path/to/metalsmith.json | ||
Metalsmith · successfully built to: /path/to/build | ||
## Javascript API | ||
## API | ||
#### new Metalsmith(dir) | ||
Create a new `Metalsmith` instance for a working `dir`. | ||
Create a new `Metalsmith` instance for a working `dir`. | ||
#### #use(plugin) | ||
Add the given `plugin` function to the middleware stack. | ||
Add the given `plugin` function to the middleware stack. | ||
#### #build(fn) | ||
Build with the given settings and call `fn(err, files)`. | ||
#### #source(path) | ||
Set the relative `path` to the source directory, or get the full one if no `path` is provided. The source directory defaults to `./src`. | ||
Set the relative `path` to the source directory, or get the full one if no `path` is provided. The source directory defaults to `./src`. | ||
#### #destination(path) | ||
Set the relative `path` to the destination directory, or get the full one if no `path` is provided. The destination directory defaults to `./build`. | ||
Set the relative `path` to the destination directory, or get the full one if no `path` is provided. The destination directory defaults to `./build`. | ||
#### #metadata(json) | ||
Set global metadata that should be applied to each file, in addition to any YAML front-matter. | ||
Get the global metadata. This is useful for plugins that want to set global-level metadata that can be applied to all files. | ||
#### #join(paths...) | ||
Join any amount of `paths...` to the working directory. | ||
Join any amount of `paths...` to the working directory. This is useful for plugins who want to read extra assets from another directory, for example `./templates`. | ||
#### #build(fn) | ||
## License | ||
Build with the given settings and plugins, and call `fn(err)`. | ||
The MIT License (MIT) | ||
## License | ||
Copyright © 2013, Segment.io \<friends@segment.io\> | ||
MIT | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
4
145
2
11638
8
7
142
+ Addedchalk@^0.4.0
+ Addedansi-styles@1.0.0(transitive)
+ Addedchalk@0.4.0(transitive)
+ Addedhas-color@0.1.7(transitive)
+ Addedstrip-ansi@0.1.1(transitive)