From aef34f1628e700bc6cd980e0c59d9e7336b35c6c Mon Sep 17 00:00:00 2001 From: Jidesh Veeramachaneni Date: Mon, 23 Jan 2017 23:31:41 +0800 Subject: [PATCH] feat: add locale and include to entries query --- docs/source-file-settings.md | 34 ++++++++++++++++++++++++++++++++++ lib/util.js | 2 +- test/index.spec.js | 20 ++++++++++++++++++++ test/src/posts-include.html | 8 ++++++++ test/src/posts-locale.html | 8 ++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 test/src/posts-include.html create mode 100644 test/src/posts-locale.html diff --git a/docs/source-file-settings.md b/docs/source-file-settings.md index 9e67f8f..414beb3 100644 --- a/docs/source-file-settings.md +++ b/docs/source-file-settings.md @@ -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** @@ -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** diff --git a/lib/util.js b/lib/util.js index 4439837..6da97e6 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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) diff --git a/test/index.spec.js b/test/index.spec.js index 2bffb14..9628478 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -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: { @@ -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 // @@ -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 // diff --git a/test/src/posts-include.html b/test/src/posts-include.html new file mode 100644 index 0000000..cfbc748 --- /dev/null +++ b/test/src/posts-include.html @@ -0,0 +1,8 @@ +--- +title: test__posts +contentful: + content_type: 2wKn6yEnZewu2SCCkus4as + include: 0 +layout: posts.html +--- +POSTS-INCLUDE diff --git a/test/src/posts-locale.html b/test/src/posts-locale.html new file mode 100644 index 0000000..de62919 --- /dev/null +++ b/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