-
Notifications
You must be signed in to change notification settings - Fork 32
Adds support for global key #42
base: master
Are you sure you want to change the base?
Changes from all commits
e7341c0
e502960
c477a9f
a9f0184
1516563
d377519
46d6372
1f8bc9c
42e5bb8
9f28d95
a8602b5
939ad45
240f079
497b4b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,12 @@ To get an idea on how this works, you can check out an [example blog site](https | |
### Install | ||
|
||
```bash | ||
$ npm install contentful-metalsmith | ||
$ npm install contentful-metalsmith --save | ||
``` | ||
|
||
### Configure required globals | ||
|
||
When you use metalsmith using the [cli](https://github.com/metalsmith/metalsmith#cli) edit your `metalsmith.json` and add `contentful-metalsmith` in the plugins section. | ||
When using the [metalsmith cli](https://github.com/metalsmith/metalsmith#cli) you can edit your `metalsmith.json` and add `contentful-metalsmith` in the plugins section. | ||
|
||
```javascript | ||
// metalsmith.json | ||
|
@@ -33,7 +33,12 @@ When you use metalsmith using the [cli](https://github.com/metalsmith/metalsmith | |
"plugins": { | ||
"contentful-metalsmith": { | ||
"access_token": "YOUR_CONTENTFUL_ACCESS_TOKEN", | ||
"space_id": "YOUR_CONTENTFUL_SPACE_ID" | ||
"space_id": "YOUR_CONTENTFUL_SPACE_ID", | ||
"entry_key": "_key", | ||
"entry_extension": "md", | ||
"contentful": { | ||
"content_type": "2wKn6yEnZewu2SCCkus4as" | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -45,13 +50,22 @@ When you use the [JavaScript Api](https://github.com/metalsmith/metalsmith#api) | |
metalsmith.source('src') | ||
metalsmith.destination('build') | ||
|
||
metalsmith.use(require('contentful-metalsmith')({ 'access_token' : 'YOUR_CONTENTFUL_ACCESS_TOKEN' })) | ||
metalsmith.use(require('contentful-metalsmith')({ | ||
'access_token': 'YOUR_CONTENTFUL_ACCESS_TOKEN', | ||
'entry_key': '_key', | ||
'entry_extension': 'md', | ||
'contentful': { | ||
'content_type': '2wKn6yEnZewu2SCCkus4as' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would change this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, was wondering about that. Is that fetching all the data under that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cameronroe yes it is fetching entries under that contentType There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. What would be the best way to configure fetching all data from Contentful for users who want to build a site with multiple |
||
} | ||
})) | ||
``` | ||
|
||
**Global parameters:** | ||
|
||
- `acccess_token` | ||
- `space_id` | ||
- `entry_key` | ||
- `entry_extension` | ||
|
||
You can find the `access_token` and `space_id` in your [app](https://app.contentful.com) at `APIs -> Content delivery API Keys`. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,12 @@ You can find these in your [app](https://app.contentful.com) at `APIs -> Content | |
"contentful-metalsmith": { | ||
"access_token" : "YOUR_CONTENTFUL_ACCESS_TOKEN", | ||
"space_id": "YOUR_CONTENTFUL_SPACE_ID", | ||
"host": "preview.contentful.com" | ||
"host": "preview.contentful.com", | ||
"entry_key": "_key", | ||
"entry_extension": "md", | ||
"contentful": { | ||
"content_type": "2wKn6yEnZewu2SCCkus4as" | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -50,6 +55,16 @@ For using the [Content Delivery API](https://www.contentful.com/developers/docs/ | |
|
||
*Recommended way here is to set the `host` in the `metalsmith.json` or global config and overwrite it if needed in depending source files.* | ||
|
||
### `entry_key` *(optional)* | ||
|
||
If you want to transform Contentful data into pages you can specify a `entry_key` which will be used to replace the key of all file objects with the stored Contentful key path. You must specify a path to the file as if it was referenced from your `src` directory and exclude the extension. | ||
|
||
For example, if you specify `entry_key`: `_key`, then create a Contentful entry with a `_key` property set to `pages/index` a file will be referenced in Metalsmith with `pages/index.md` (assuming you specify `entry_extension` as `md`) | ||
|
||
### `entry_extension` *(optional)* | ||
|
||
If you specify `entry_key`, you will need to specify the entry extension for all file keys. This will be appended to the key on Contentful entries that contain the `entry_key`. | ||
|
||
### `filterTransforms` *(optional)* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like we need a lot more documentation now... And maybe update the getting started guide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, do you think there should be another section similar to this one? I could write up a longer description under this section and then link it to the |
||
|
||
If you want to use dynamic values in a source file's filter query, you can provide an object containing named functions that will be invoked during the metalsmith build. For example, if you provide a configuration like this: | ||
|
@@ -82,6 +97,8 @@ layout: posts.html | |
--- | ||
``` | ||
|
||
### [`contentful` *(optional)*](source-file-settings.md) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs definitely more explanation. :) |
||
|
||
### `common` *(optional)* | ||
|
||
The results of queries placed in this property will be made available in all templates | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>Home Page Content</p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module.exports = { | ||
items: [{ | ||
sys: { | ||
id: '1asN98Ph3mUiCYIYiiqwko', | ||
space: 'w7sdyslol3fu', | ||
type: 'Entry', | ||
createdAt: '2015-01-30T12:45:03.282Z', | ||
updatedAt: '2015-01-30T13:01:37.936Z', | ||
revision: 2, | ||
locale: 'en-US', | ||
contentType: { | ||
sys: { | ||
id: 'boing' | ||
} | ||
} | ||
}, | ||
fields: { | ||
name: 'John Doe', | ||
_key: 'pages/index', | ||
layout: 'post.html', | ||
contents: 'Home Page Content', | ||
category: [], | ||
tags: [], | ||
date: '1865-11-26', | ||
comments: false | ||
} | ||
}] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~~Is the contentful property correct here?~~~
Found it.