mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 07:51:55 +03:00
f0f0735437
refs #9192 - an entry is a post or a page, represented by a post model
43 lines
1.0 KiB
JavaScript
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
|
|
};
|