Vulcan/packages/telescope-daily/lib/client/templates/posts_daily.js

41 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-08-27 10:23:56 +09:00
var getPosts = function (date) {
var terms = {
view: 'digest',
after: moment(date).startOf('day').toDate(),
before: moment(date).endOf('day').toDate()
};
var parameters = getParameters(terms);
var posts = Posts.find(parameters.find, parameters.options).map(function (post, index, cursor) {
post.rank = index;
return post;
});
return posts;
}
2014-08-27 09:24:37 +09:00
Template[getTemplate('postsDaily')].helpers({
post_item: function () {
return getTemplate('post_item');
},
2014-08-27 10:23:56 +09:00
days: function () {
console.log(this)
var daysArray = [];
for (i = 0; i < this.days; i++) {
daysArray.push({
date: moment().subtract('days', i).startOf('day').toDate()
2014-08-27 09:24:37 +09:00
});
}
2014-08-27 10:23:56 +09:00
return daysArray;
},
posts: function () {
return getPosts(this.date);
2014-08-27 09:24:37 +09:00
},
hasMorePosts: function(){
// as long as we ask for N posts and all N posts showed up, then keep showing the "load more" button
return parseInt(Session.get('postsLimit')) == this.postsCount
},
loadMoreUrl: function () {
var count = parseInt(Session.get('postsLimit')) + parseInt(getSetting('postsPerPage', 10));
var categorySegment = Session.get('categorySlug') ? Session.get('categorySlug') + '/' : '';
return '/' + Session.get('view') + '/' + categorySegment + count;
}
});