Skip to content

Commit

Permalink
Update readme (#135)
Browse files Browse the repository at this point in the history
* Update readme

* Use nunjucks in example
  • Loading branch information
ismay authored Jan 15, 2018
1 parent cc1d46f commit 2b88dfe
Showing 1 changed file with 62 additions and 65 deletions.
127 changes: 62 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,63 @@
> A metalsmith plugin for rendering templates to html
This plugin allows you to render various templating languages to html. It uses file extensions to
infer which templating engine to use. So files ending in `.md` will be processed as markdown, `.hbs`
as handlebars, etc. You can even chain transformations by appending multiple extensions, which will
be processed right-to-left.
infer which templating engine to use. So files ending in `.njk` will be processed as nunjucks, `.pug` as pug, etc. You can even chain transformations by appending multiple extensions, which will be processed right-to-left.

```
For support questions please use [stack overflow][stackoverflow-url] or our [slack channel][slack-url]. For templating engine specific questions try the aforementioned channels, as well as the documentation for [jstransformers](https://github.com/jstransformers) and your templating engine of choice.

## Installation

```bash
$ npm install metalsmith-in-place
```

For support questions please use [stack overflow][stackoverflow-url] or our
[slack channel][slack-url].
## Options

You can pass options to `metalsmith-layouts` with the [Javascript API](https://github.com/segmentio/metalsmith#api) or [CLI](https://github.com/segmentio/metalsmith#cli). The options are:

* [pattern](#pattern): optional. Only files that match this pattern will be processed. Accepts a string or an array of strings. The default is `**`.
* [engineOptions](#engineoptions): optional. Use this to pass options to the jstransformer that's rendering your layouts. The default is `{}`.

### `pattern`

Only files that match this pattern will be processed. So this `metalsmith.json`:

```json
{
"source": "src",
"destination": "build",
"plugins": {
"metalsmith-in-place": {
"pattern": "blog/**/*"
}
}
}
```

Would only process files within the `./src/blog` folder, because the pattern is
relative to your source folder. See [multimatch](https://github.com/sindresorhus/multimatch)
for further details.

### `engineOptions`

Use this to pass options to the jstransformer that's rendering your templates. So this
`metalsmith.json`:

```json
{
"source": "src",
"destination": "build",
"plugins": {
"metalsmith-in-place": {
"engineOptions": {
"cache": false
}
}
}
}
```

Would pass `{ "cache": false }` to each used jstransformer.

## Example

Expand All @@ -28,7 +75,7 @@ You can use `metalsmith-in-place` with metalsmith's

### 1. Install metalsmith and metalsmith-in-place:

```
```bash
$ npm install --save metalsmith metalsmith-in-place
```

Expand All @@ -45,10 +92,10 @@ handlebars you would install
[this dictionary](https://github.com/jstransformers/inputformat-to-jstransformer/blob/master/dictionary.json)
to see which extensions map to which jstransformer.

In this case we'll use handlebars, so we'll install jstransformer-handlebars:
In this case we'll use nunjucks, so we'll install `jstransformer-nunjucks`:

```
$ npm install --save jstransformer-handlebars
```bash
$ npm install --save jstransformer-nunjucks
```

### 3. Configure metalsmith
Expand All @@ -58,7 +105,7 @@ process:

`./metalsmith.json`

```
```json
{
"source": "src",
"destination": "build",
Expand All @@ -68,9 +115,9 @@ process:
}
```

`./src/index.hbs`
`./src/index.njk`

```handlebars
```nunjucks
---
title: This is a variable, defined in the file's frontmatter
---
Expand All @@ -82,69 +129,19 @@ title: This is a variable, defined in the file's frontmatter

To build just run the metalsmith CLI:

```
```bash
$ node_modules/.bin/metalsmith
```

Which will output the following file:

`./build/index.html`

```
```html
<h1>This is a variable, defined in the file's frontmatter</h1>
<p>Some text here.</p>
```

## Options

* `engineOptions`: optional. Use this to pass options to the jstransformer that's rendering your
templates. The default is `{}`.

* `pattern`: optional. By default this plugin tries to process all files. If you encounter problems
use this option to filter. Only files that match this pattern will be processed. Accepts a string or
an array of strings. The default is `**`.

### `engineOptions`

Use this to pass options to the jstransformer that's rendering your templates. So this
`metalsmith.json`:

```json
{
"source": "src",
"destination": "build",
"plugins": {
"metalsmith-in-place": {
"engineOptions": {
"cache": false
}
}
}
}
```

Would pass `{ "cache": false }` to each used jstransformer.

### `pattern`

Only files that match this pattern will be processed. So this `metalsmith.json`:

```json
{
"source": "src",
"destination": "build",
"plugins": {
"metalsmith-in-place": {
"pattern": "blog/**/*"
}
}
}
```

Would only process files within the `./src/blog` folder, because the pattern is
relative to your source folder. See [multimatch](https://github.com/sindresorhus/multimatch)
for further details.

## Credits

* [Ian Storm Taylor](https://github.com/ianstormtaylor) for creating [metalsmith-templates](https://github.com/segmentio/metalsmith-templates), on which this plugin was based
Expand Down

0 comments on commit 2b88dfe

Please sign in to comment.