Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

contentful-metalsmith

Package Overview
Dependencies
Maintainers
5
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful-metalsmith - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

28

docs/global-settings.md

@@ -75,3 +75,3 @@ # Global settings

---
title: Post overview of entries including "rabbit"
title: Articles with certain start and end dates
contentful:

@@ -85,1 +85,27 @@ content_type: post

```
### `common` *(optional)*
The results of queries placed in this property will be made available in all templates
For example, find your five latest entries so you can include them in various templates:
```javascript
{
// ...
"common": {
"latest": {
"content_type": "post",
"limit": 5,
"order": "sys.createdAt"
}
},
// ...
}
```
In templates you can then access `common.latest` to get the raw results of the above query:
```
The first latest post's title, in handlebars syntax: {{ common.latest.items.0.fields.title }}
```

@@ -13,2 +13,3 @@ 'use strict'

* @param {String} spaceId space id
* @param {String} host host
*

@@ -30,2 +31,44 @@ * @return {Object} contentful client

/**
* Fetch common content for a certain space.
*
* @param {Object} entries entries fetched from contentful
* @param {Object} options plugin config
*
* @return {Object} file mapping object with common content added
*/
function getCommonContentForSpace (entries, options) {
if (!options.common) {
return entries
}
const client = getContentfulClient(options.access_token, options.space_id, options.host)
const commonQueries = []
const commonIds = []
for (let id in options.common) {
commonQueries.push(client.getEntries(util.getEntriesQuery(options.common[id], options.filterTransforms)))
commonIds.push(id)
}
// First, execute all common queries.
return Promise.all(commonQueries).then(commonContent => {
return new Promise((resolve, reject) => {
// Store the results in an object using the configured IDs.
const commonsObj = commonIds.reduce((prev, curr, index) => {
prev[curr] = commonContent[index]
return prev
}, {})
// Assign common query results to each entry.
for (let entry in entries) {
entries[entry].common = commonsObj
}
resolve(entries)
})
})
}
/**
* Enrich all fetched entries with additional properties

@@ -126,2 +169,3 @@ *

.then(entries => processEntriesForFile(file, entries))
.then(entries => getCommonContentForSpace(entries, options))
}

@@ -128,0 +172,0 @@

2

package.json

@@ -46,3 +46,3 @@ {

},
"version": "0.4.0"
"version": "0.5.0"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc