contentful-metalsmith
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "contentful-metalsmith", | ||
"version": "0.1.0", | ||
"description": "A Metalsmith's plugin to get content from Contentful", | ||
"main": "lib/index.js", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:contentful/contentful-metalsmith.git" | ||
"url": "https://github.com/contentful-labs/contentful-metalsmith.git" | ||
}, | ||
"author": "Contentful GmbH", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/contentful/contentful-metalsmith/issues" | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"homepage": "https://github.com/contentful/contentful-metalsmith", | ||
"dependencies": { | ||
"async": "^0.9.0", | ||
"contentful": "^0.1.2", | ||
"debug": "^1.0.3", | ||
"lodash": "^2.4.1" | ||
} | ||
} | ||
"contentful": "^3.5.0", | ||
"lodash.pick": "^4.4.0", | ||
"lodash.template": "^4.4.0", | ||
"slug-component": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.16.0", | ||
"coveralls": "^2.11.12", | ||
"cz-conventional-changelog": "^1.2.0", | ||
"eslint": "^3.3.1", | ||
"eslint-config-standard": "^6.0.0-beta.3", | ||
"eslint-plugin-promise": "^2.0.1", | ||
"eslint-plugin-standard": "^2.0.0", | ||
"handlebars": "^4.0.5", | ||
"metalsmith": "^2.2.0", | ||
"metalsmith-layouts": "^1.6.5", | ||
"nyc": "^8.1.0", | ||
"proxyquire": "^1.7.10", | ||
"semantic-release": "^4.3.5" | ||
}, | ||
"scripts": { | ||
"coveralls": "nyc report --reporter=text-lcov | coveralls", | ||
"lint": "eslint \"**/*.js\"", | ||
"test": "npm run lint && nyc ava **/*.spec.js", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"version": "0.2.0" | ||
} |
211
README.md
# contentful-metalsmith | ||
[![Build Status](https://travis-ci.org/contentful-labs/contentful-metalsmith.svg?branch=master)](https://travis-ci.org/contentful-labs/contentful-metalsmith) | ||
[![Coverage Status](https://coveralls.io/repos/github/contentful-labs/contentful-metalsmith/badge.svg?branch=refactor)](https://coveralls.io/github/contentful-labs/contentful-metalsmith?branch=refactor) | ||
A Metalsmith's plugin to get content from [Contentful](http://www.contentful.com) | ||
A Metalsmith' plugin to generate files using content from [Contentful](http://www.contentful.com) | ||
## About | ||
This plugin for [metalsmith](http://www.metalsmith.io) allows you to build a static site using the data stored at [Contentful](http://www.contentful.com). This | ||
plugin is built on top of the [Contentful JavaScript Client](https://github.com/contentful/contentful.js). | ||
This plugin for [metalsmith](http://www.metalsmith.io) allows you to build a static site using the data stored at [Contentful](http://www.contentful.com). It is built on top of the [Contentful JavaScript Client](https://github.com/contentful/contentful.js). | ||
## TL;DR | ||
## Getting started | ||
1. Install it | ||
### Install | ||
```javascript | ||
$ npm install contentful-metalsmith | ||
``` | ||
2. Configure it (example for [metalsmith CLI](https://github.com/segmentio/metalsmith#cli)) | ||
```bash | ||
$ npm install contentful-metalsmith | ||
``` | ||
```javascript | ||
$ vim metalsmith.json | ||
### 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. | ||
{ | ||
"source": "src", | ||
"destination": "build", | ||
"plugins": { | ||
..., | ||
"contentful-metalsmith": { | ||
"accessToken" : "YOUR_CONTENTFUL_ACCESS_TOKEN" | ||
}, | ||
... | ||
} | ||
```javascript | ||
// metalsmith.json | ||
{ | ||
"source": "src", | ||
"destination": "build", | ||
"plugins": { | ||
"contentful-metalsmith": { | ||
"access_token": "YOUR_CONTENTFUL_ACCESS_TOKEN", | ||
"space_id": "YOUR_CONTENTFUL_SPACE_ID" | ||
} | ||
``` | ||
} | ||
} | ||
``` | ||
3. Create a source file | ||
When you use the [JavaScript Api](https://github.com/metalsmith/metalsmith#api) add `contentful-metalsmith` to the used plugins. | ||
```html | ||
```javascript | ||
metalsmith.source('src') | ||
metalsmith.destination('build') | ||
--- | ||
title: OMG metalsmith-contentful | ||
contentful: | ||
space_id: AN_SPACE_ID | ||
template: entries.html | ||
--- | ||
metalsmith.use(require('contentful-metalsmith')({ 'access_token' : 'YOUR_CONTENTFUL_ACCESS_TOKEN' })) | ||
``` | ||
[OPTIONAL CONTENT] | ||
``` | ||
**Global parameters:** | ||
4. Create the template (handlebarsjs on this case) | ||
- `acccess_token` | ||
- `space_id` | ||
```html | ||
<!doctype html> | ||
You can find the `access_token` and `space_id` in your [app](https://app.contentful.com) at `APIs -> Content delivery API Keys`. | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
------------------------------ | ||
<title>Contentful-metalsmith plugin example</title> | ||
<meta name="description" content="No description"> | ||
<meta name="author" content="Contentful"> | ||
To read more on all global parameters and settings read the [global settings documentation](./docs/global-settings.md). | ||
</head> | ||
### Create files based on the files defined in your source folder | ||
<body> | ||
We're considering that you use [metalsmith-layouts](https://github.com/superwolff/metalsmith-layouts) for file rendering. That for the `layout` key is used for rendered source files and child templates. | ||
{{contents}} | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Type</th> | ||
<th>Id</th> | ||
<th>Updated</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{{#each contentful.entries}} | ||
<tr> | ||
<td> | ||
{{this.data.sys.contentType.sys.id}} | ||
</td> | ||
<td> | ||
{{this.data.sys.id}} | ||
</td> | ||
<td> | ||
{{this.data.sys.updatedAt}} | ||
</td> | ||
</tr> | ||
{{/each}} | ||
</tbody> | ||
</table> | ||
</body> | ||
</html> | ||
``` | ||
*`source/posts.html`* | ||
5. Enjoy | ||
```markdown | ||
--- | ||
title: metalsmith-contentful file | ||
contentful: | ||
content_type: post | ||
layout: post.html | ||
layout: posts.html | ||
--- | ||
# Usage | ||
[OPTIONAL CONTENT] | ||
``` | ||
The first thing that you have to do to use this plugin is to install and configure it (see the TL;DR section for that). Once you have done this you can create and setup source files to fetch data from [Contentful](http://www.contentful.com). | ||
*`layouts/posts.html`* | ||
## Setup a source file | ||
```html | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>{{title}}</title> | ||
<meta name="description" content="No description"> | ||
<meta name="author" content="Contentful"> | ||
<link rel="stylesheet" href="scss/style.css?v=1.0"> | ||
</head> | ||
<body> | ||
<ul> | ||
<!-- available data fetched from contentful --> | ||
{{#each data.entries }} | ||
<li> | ||
<h2>{{fields.title}}</h2> | ||
<p>{{fields.description}}</p> | ||
<p><a href="{{_fileName}}">Read more</a></p> | ||
</li> | ||
{{/each}} | ||
</ul> | ||
{{contents}} | ||
</body> | ||
</html> | ||
``` | ||
To fetch data from [Contentful](http://www.contentful.com) you have to include some extra metadata in a metalsmith source file. The available configuration parameters are the following: | ||
*`layouts/post.html`* | ||
* `space_id` (**required**), the id of the space from where you want to get entries. | ||
* `entry_template` (optional), the template that will be used to render each individual entry. | ||
* `filter` (optional), this parameter has to include some of the [filtering options](https://www.contentful.com/developers/documentation/content-delivery-api/http/#search) offered by the [Contentful's Content Delivery API](https://www.contentful.com/developers/documentation/content-delivery-api/). | ||
```html | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>{{data.fields.title}}</title> | ||
<meta name="description" content="No description"> | ||
<meta name="author" content="Contentful"> | ||
<link rel="stylesheet" href="scss/style.css?v=1.0"> | ||
</head> | ||
<body> | ||
<h1>{{data.fields.title}}<h1> | ||
<p>{{data.fields.description}}</p> | ||
All this parameters have to be nested under the key `contentful`. | ||
An example: | ||
```yaml | ||
--- | ||
title: OMG metalsmith-contentful | ||
contentful: | ||
space_id: cfexampleapi | ||
content_type: cat | ||
filter: | ||
sys.id[in]: 'finn,jake' | ||
entry_template: entry.html | ||
template: example.html | ||
--- | ||
{{contents}} | ||
</body> | ||
</html> | ||
``` | ||
## Using the fetched entries on the templates | ||
**This example will** | ||
We have to make a distinction between two types of templates: | ||
- render `posts.html` providing data of the entries of content type `post` | ||
- render several single files with the template `post.html` providing the data of a particular post | ||
* The template rendered for the source file. | ||
* And the template rendered for each individual entry. | ||
------------------------------ | ||
In the context of the template rendered for the source file you will have access to a property named `contentful`. This property holds the following properties: | ||
To read more on source file parameters and settings read the [source file documentation](./docs/source-file-settings.md). | ||
* `entries`, an array with all the fetched entries. The structure of each of this entry objects will be the same as the explained below for the entry template. | ||
* `contentTypes`, an object with the id of the fetched [contentTypes](https://www.contentful.com/developers/documentation/content-delivery-api/http/#content-types) as keys. Under each key there will be an array with all the entries belonging to that particular contentType. | ||
In the context of the template rendered for an individual entry you will have access to the following properties under the property `data`: | ||
* `id`, a shortcut to the entry's id. | ||
* `contentType`, a shortcut to the entry's contentType. | ||
* `data`, the body of the entry as returned by [Contentful's Content Delivery API](https://www.contentful.com/developers/documentation/content-delivery-api/) | ||
# License | ||
MIT | ||
MIT |
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
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
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
24818
12
333
13
2
2
136
2
+ Addedlodash.pick@^4.4.0
+ Addedlodash.template@^4.4.0
+ Addedslug-component@^1.1.0
+ Addedbabel-runtime@6.3.19(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcontentful@3.8.1(transitive)
+ Addedcontentful-sdk-core@2.5.0(transitive)
+ Addedcore-js@1.2.7(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfollow-redirects@0.0.7(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.1.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedlodash@4.2.1(transitive)
+ Addedlodash._reinterpolate@3.0.0(transitive)
+ Addedlodash.pick@4.4.0(transitive)
+ Addedlodash.template@4.5.0(transitive)
+ Addedlodash.templatesettings@4.2.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedqs@6.13.1(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedslug-component@1.1.0(transitive)
+ Addedstream-consume@0.1.1(transitive)
- Removedasync@^0.9.0
- Removeddebug@^1.0.3
- Removedlodash@^2.4.1
- Removedasync@0.9.2(transitive)
- Removedbl@0.7.0(transitive)
- Removedbluebird@0.11.6(transitive)
- Removedcontentful@0.1.2(transitive)
- Removedcontentful-resolve-response@0.1.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddebug@1.0.5(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@0.0.1(transitive)
- Removedlodash@2.4.2(transitive)
- Removedprocess@0.5.2(transitive)
- Removedquestor@1.0.0-alpha.2(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedredefine@0.2.1(transitive)
- Removedstream-browserify@0.1.3(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedunderscore@1.13.7(transitive)
- Removedunderscore-contrib@0.2.2(transitive)
Updatedcontentful@^3.5.0