Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
feat: add locale and include to entries query
Browse files Browse the repository at this point in the history
  • Loading branch information
jideshv authored and Khaledgarbaya committed Jan 23, 2017
1 parent 787f4fd commit aef34f1
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
34 changes: 34 additions & 0 deletions docs/source-file-settings.md
Expand Up @@ -225,6 +225,23 @@ Post that include rabbits are...

If you want to learn more about the filter syntax, check out the [Content Delivery API documentation](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters).

### `include` *(optional)*

**Retrieval of linked items (maximum of 10 levels)**

```markdown
---
title: Posts with up to 10 levels of linked items retrieved
contentful:
content_type: post
include: 10
layout: posts.html
---
posts with retrieved links are...
```

If you want to learn more about retrieval of linked items, check out the [Content Delivery API documentation](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/links).

### `limit` *(optional)*

**Limit the entries before rendering to one or multiple files**
Expand All @@ -242,6 +259,23 @@ layout: posts.html

If you want to learn more about limits, check out the [Content Delivery API documentation](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/limit).

### `locale` *(optional)*

**Specify the locale used for entries**

```markdown
---
title: Posts in Traditional Chinese Hong Kong
contentful:
content_type: post
locale: zh-Hant-HK
layout: posts.html
---
posts in Traditional Chinese Hong Kong are...
```

If you want to learn more about locales, check out the [Content Delivery API documentation](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/localization).

### `order` *(optional)*

**Order the entries before rendering to one or multiple files**
Expand Down
2 changes: 1 addition & 1 deletion lib/util.js
Expand Up @@ -5,7 +5,7 @@ const pick = require('lodash.pick')
const template = require('lodash.template')
const slug = require('slug-component')

const propertiesToPickEasily = ['limit', 'order']
const propertiesToPickEasily = ['locale', 'include', 'limit', 'order']
const notFoundKey = '__not-available__'
const notFoundRegex = new RegExp(notFoundKey)

Expand Down
20 changes: 20 additions & 0 deletions test/index.spec.js
Expand Up @@ -14,8 +14,12 @@ test__posts__permalinks-POSTS-CONTENT-PERMALINKS\n`,
test__posts__extentsion-POSTS-CONTENT-EXTENSION\n`,
postsFiltered: `Down the Rabbit Hole
test__posts__filtered-POSTS-CONTENT-FILTERED\n`,
postsInclude: `Down the Rabbit HoleSeven Tips From Ernest Hemingway on How to Write Fiction
test__posts-POSTS-INCLUDE\n`,
postsLimited: `Down the Rabbit Hole
test__posts__limited-POSTS-CONTENT-LIMITED\n`,
postsLocale: `Down the Rabbit HoleSeven Tips From Ernest Hemingway on How to Write Fiction
test__posts__locale-POSTS-CONTENT-LOCALE\n`,
postsOrdered: `Seven Tips From Ernest Hemingway on How to Write FictionDown the Rabbit Hole
test__posts__ordered-POSTS-CONTENT-ORDERED\n`,
posts: {
Expand Down Expand Up @@ -99,6 +103,14 @@ test.serial.cb('e2e - it should render all templates properly', t => {
expectedResults.postsFiltered
)

//
// render include posts
//
t.is(
fs.readFileSync(`${__dirname}/build/posts-include.html`, { encoding: 'utf8' }),
expectedResults.postsInclude
)

//
// render limited posts
//
Expand All @@ -107,6 +119,14 @@ test.serial.cb('e2e - it should render all templates properly', t => {
expectedResults.postsLimited
)

//
// render locale posts
//
t.is(
fs.readFileSync(`${__dirname}/build/posts-locale.html`, { encoding: 'utf8' }),
expectedResults.postsLocale
)

//
// render ordered posts
//
Expand Down
8 changes: 8 additions & 0 deletions test/src/posts-include.html
@@ -0,0 +1,8 @@
---
title: test__posts
contentful:
content_type: 2wKn6yEnZewu2SCCkus4as
include: 0
layout: posts.html
---
POSTS-INCLUDE
8 changes: 8 additions & 0 deletions test/src/posts-locale.html
@@ -0,0 +1,8 @@
---
title: test__posts__locale
contentful:
content_type: 2wKn6yEnZewu2SCCkus4as
locale: en-US
layout: posts.html
---
POSTS-CONTENT-LOCALE

0 comments on commit aef34f1

Please sign in to comment.