# metalsmith-cockpit

A [Metalsmith](https://metalsmith.io) plugin to retrieve content from the [Cockpit](https://getcockpit.com) API

## Installation

```
npm install --save metalsmith-cockpit
```

Or if you prefer to use Yarn...

```
yarn add metalsmith-cockpit
```

## CLI Usage

```
{
    "plugins": {
        "metalsmith-cockpit": {
            "resourceType": "collections",
            "resourceName": "posts",
            "resourceFilter: { "published": true },
            "destination": "./articles"
        }
    }
}
```

## JavaScript Usage

```
const metalsmith = require('metalsmith')
const cockpit = require('metalsmith-cockpit')

metalsmith.use(cockpit({
    cockpitApiUrl: process.env.COCKPIT_API_URL,
    cockpitApiToken: process.env.COCKPIT_API_TOKEN,
    resourceType: 'collections',
    resourceName: 'posts',
    resourceFilter: { published: true },
    destination: './articles'
}))
```

### Available Options

* `cockpitApiUrl` - **required**
    - URL for Cockpit API (e.g. http://localhost/api)
* `cockpitApiToken` - **required**
    - Valid API token to `GET` the required resource type / name
* `resourceName` - **required**
    - The name of the resource in Cockpit (this will be the collection name, singleton name, etc)
* `resourceType` - default `collections`
    - The type of resource we're retrieving - must be a valid type within Cockpit (collections, forms, singletons)
* `resourceFilter` - default `{}`
    - A hash of filters that will be included in the request to the Cockpit API (e.g. `{ published: true })
* `destination` - default `./`
    - The directory the entries will be output into
* `collection` - default `resourceName`
    - If you're using the `metalsmith-collections` plugin you can set the name of the collection entries will be added to via metadata

