2014-01-18 16:52:12 +09:00
|
|
|
serveAPI = function(limitSegment){
|
|
|
|
var posts = [];
|
2014-06-27 19:57:30 +09:00
|
|
|
var limit = typeof limitSegment === 'undefined' ? 20 : limitSegment // default limit: 20 posts
|
2014-01-18 16:52:12 +09:00
|
|
|
|
2014-07-03 14:26:05 +09:00
|
|
|
Posts.find({status: STATUS_APPROVED}, {sort: {postedAt: -1}, limit: limit}).forEach(function(post) {
|
2014-08-04 11:22:43 +09:00
|
|
|
var url = getPostLink(post);
|
2014-01-18 16:52:12 +09:00
|
|
|
var properties = {
|
2014-05-16 09:19:35 +09:00
|
|
|
title: post.title,
|
|
|
|
headline: post.title, // for backwards compatibility
|
2014-01-18 16:52:12 +09:00
|
|
|
author: post.author,
|
2014-07-03 14:26:05 +09:00
|
|
|
date: post.postedAt,
|
2014-01-18 16:52:12 +09:00
|
|
|
url: url,
|
|
|
|
guid: post._id
|
|
|
|
};
|
|
|
|
|
|
|
|
if(post.body)
|
2014-05-06 20:15:48 -07:00
|
|
|
properties.body = post.body;
|
2014-01-18 16:52:12 +09:00
|
|
|
|
|
|
|
if(post.url)
|
2014-05-06 20:15:48 -07:00
|
|
|
properties.domain = getDomain(url);
|
2014-01-18 16:52:12 +09:00
|
|
|
|
|
|
|
if(twitterName = getTwitterNameById(post.userId))
|
2014-05-06 20:15:48 -07:00
|
|
|
properties.twitterName = twitterName;
|
2014-01-18 16:52:12 +09:00
|
|
|
|
|
|
|
posts.push(properties);
|
|
|
|
});
|
|
|
|
|
|
|
|
return JSON.stringify(posts);
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|