Ghost/core/server/controllers/frontend/format-response.js
Hannah Wolfe f0f0735437 Renamed single / post -> entry
refs #9192

- an entry is a post or a page, represented by a post model
2017-11-08 10:07:52 +00:00

43 lines
1.0 KiB
JavaScript

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
*/
function formatPageResponse(result) {
var response = {
posts: result.posts,
pagination: result.meta.pagination
};
_.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;
}
/**
* similar to formatPageResponse, but for entries (post or page)
* @return {Object} containing page variables
*/
function formatResponse(post) {
return {
post: post
};
}
module.exports = {
channel: formatPageResponse,
entry: formatResponse
};