Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added most active threads to index page

  • Loading branch information...
commit 12226c71cecba05e376a0e7fd9cb37a47e525367 1 parent d77bf70
@SlashmanX authored
View
26 app.js
@@ -79,12 +79,20 @@ if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
-app.get('/', routes.index);
+app.get('/', function(req, res) {
+ getActiveThreads(function(err, data) {
+ var active = data.data.data;
+ res.render('home', {title: 'Home', activeThreads: active});
+ })
+});
app.get('/r/:subreddit/', function(req, res) {
- res.render('index', { title: req.params.subreddit, subreddit: req.params.subreddit });
+ res.render('stream', { title: req.params.subreddit, subreddit: req.params.subreddit });
})
app.get('/r/:subreddit/comments/:topicid/:topicname?/*', function(req, res) {
- res.render('index', { title: req.params.subreddit, topic: req.params.topicid });
+ if(req.params.topicid.substring(0,3) == 't3_')
+ res.redirect('/r/'+ req.params.subreddit+'/comments/'+ req.params.topicid.replace('t3_', '')+'/');
+ else
+ res.render('stream', { title: req.params.subreddit, topic: req.params.topicid });
})
var parser = JSONStream.parse() //emit parts that match this path (any element of the rows array)
@@ -97,4 +105,14 @@ var logger = es.mapSync(function (data) {
req.pipe(parser)
parser.pipe(logger);
-server.listen(app.get('port'));
+server.listen(app.get('port'));
+
+function getActiveThreads(callback) {
+ request('http://api.redditanalytics.com/getmostactivethreads?limit=25&timespan=300', function(error, res, body) {
+ if(!error && res.statusCode == 200) {
+ callback(null, {data: JSON.parse(body)})
+ }
+ else
+ callback(error, null);
+ })
+}
View
7 views/home.jade
@@ -0,0 +1,7 @@
+extends layout
+
+block content
+ h3 Active Threads
+ .active-threads
+ - each thread in activeThreads
+ include partials/thread.jade
View
4 views/partials/thread.jade
@@ -0,0 +1,4 @@
+.panel.panel-default(id=thread.link_id)
+ .panel-heading <strong><a href="http://reddit.com/r/#{thread.subreddit}">#{thread.subreddit}</a></strong>
+ .panel-body <a href = "#{thread.link}">#{thread.title}</a><a class = 'pull-right' href = '/r/#{thread.subreddit}/comments/#{thread.link_id}/'>View Live</a>
+ .panel-footer <strong>New Comments: </strong>#{thread.new_comments} in past 5 minutes
View
0  views/index.jade → views/stream.jade
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.