2015-10-21 14:51:01 +03:00
|
|
|
var _ = require('lodash');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* formats variables for handlebars in multi-post contexts.
|
|
|
|
* If extraValues are available, they are merged in the final value
|
|
|
|
* @return {Object} containing page variables
|
|
|
|
*/
|
2015-10-24 22:04:02 +03:00
|
|
|
function formatPageResponse(result) {
|
|
|
|
var response = {
|
|
|
|
posts: result.posts,
|
|
|
|
pagination: result.meta.pagination
|
2015-10-21 14:51:01 +03:00
|
|
|
};
|
2015-10-24 22:04:02 +03:00
|
|
|
|
|
|
|
_.each(result.data, function (data, name) {
|
|
|
|
if (data.meta) {
|
|
|
|
// Move pagination to be a top level key
|
|
|
|
response[name] = data;
|
|
|
|
response[name].pagination = data.meta.pagination;
|
|
|
|
delete response[name].meta;
|
|
|
|
} else {
|
|
|
|
// This is a single object, don't wrap it in an array
|
|
|
|
response[name] = data[0];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return response;
|
2015-10-21 14:51:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* similar to formatPageResponse, but for single post pages
|
|
|
|
* @return {Object} containing page variables
|
|
|
|
*/
|
|
|
|
function formatResponse(post) {
|
|
|
|
return {
|
|
|
|
post: post
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
channel: formatPageResponse,
|
|
|
|
single: formatResponse
|
|
|
|
};
|