Skip to content

Commit

Permalink
Adding helpers to load homepage collection too
Browse files Browse the repository at this point in the history
  • Loading branch information
gja committed Jul 6, 2018
1 parent af6eb3d commit 977500a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quintype/framework",
"version": "2.56.0-template2",
"version": "2.56.0",
"description": "Libraries to help build Quintype Node.js apps",
"main": "index.js",
"scripts": {
Expand Down
24 changes: 22 additions & 2 deletions server/data-loader-helpers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// istanbul ignore file

const {Story} = require('./api-client');
const {Story, Collection} = require('./api-client');
const templateOptions = require('./template-options');

exports.catalogDataLoader = function(client, config) {
exports.catalogDataLoader = function catalogDataLoader(client, config) {
return Story.getStories(client)
.then(stories => {
return {
Expand All @@ -13,3 +13,23 @@ exports.catalogDataLoader = function(client, config) {
}
});
}

exports.homeCollectionOrStories = function homeCollectionOrStories(client) {
return Collection.getCollectionBySlug(client, "home", { 'item-type': 'collection'}, {depth: 1})
.then(collection => {
if(collection)
return collection;
else
return Story.getStories(client).then(stories => Collection.build({
slug: 'home',
name: "Home",
template: "default",
items: [{
type: 'collection',
name: "Home",
template: "default",
items: stories.map(story => ({type: 'story', story: story.asJson()}))
}]
}))
})
}

0 comments on commit 977500a

Please sign in to comment.