From 5e5cdd7e3758412851fffa56a9786ffa5d751e40 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sun, 6 Sep 2015 12:07:22 -0400 Subject: getting colors from keywords --- lib/bucky.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib/bucky.js') diff --git a/lib/bucky.js b/lib/bucky.js index ef6fbbc..9a43c0d 100644 --- a/lib/bucky.js +++ b/lib/bucky.js @@ -1,4 +1,5 @@ var db = require('./db') +var _ = require('lodash') var bucky = module.exports = { @@ -8,6 +9,7 @@ var bucky = module.exports = { db.getLatestThreads().then(function(threads){ res.threads = threads res.threads_ids = res.threads.pluck("id").sort() + res.keywords = _.uniq(res.threads.pluck("keyword")) next() }) }, @@ -33,6 +35,26 @@ var bucky = module.exports = { next() }) }, + ensureKeywordsForThreads: function (req, res, next){ + db.getKeywords(res.keywords).then(function(keywords){ + var lookup = {} + keywords.forEach(function(k){ + lookup[k.get('keyword')] = k + }) + console.log(keywords) + res.threads.forEach(function(t){ + var kw = t.get('keyword') + if (! kw) return + var k = lookup[kw] + if (! k) return + if (! t.get("color")) { + t.set("color", k.get("color")) + console.log(k.get("color")) + } + }) + next() + }) + }, ensureHootbox: function (req, res, next){ db.getCommentsForThread(1, 9).then(function(hootbox){ res.hootbox = hootbox -- cgit v1.2.3-70-g09d2