Created
February 22, 2019 16:04
-
-
Save simistern/064ff153b6a5ed6abfb226e33b2384f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor.publish('subredditSearch', function(subreddit) { | |
var self = this; | |
try { | |
var response = HTTP.get('http://reddit.com/r/' + subreddit + '.json'); | |
_.each(response.data.data.children, function(item) { | |
var data = item.data; | |
var len = 200; | |
var post = { | |
id: data.id, | |
url: data.url, | |
domain: data.domain, | |
comment_count: data.num_comments, | |
permalink: data.permalink, | |
title: data.title, | |
selftext: false, | |
thumbnail: false | |
}; | |
if (data.selftext != "") { | |
post.selftext = data.selftext.substr(0, len) | |
} | |
if (data.thumbnail != "self" && Meteor.call('isUrl', data.thumbnail)) { | |
post.thumbnail = data.thumbnail | |
} | |
self.added('posts', Random.id(), post); | |
}); | |
self.ready(); | |
} catch (error) { | |
console.log(error); | |
} | |
}); | |
Meteor.methods({ | |
isUrl: function(url) { | |
if (url.indexOf('http') > -1) { return true; } | |
return false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment