Tag List Added October 8, 2013
I recently went about aggregating the tags used on my posts to create a sort of tag cloud. I never liked the display of tag clouds, so I just list them out in order of occurrence, with the most frequent showing first.
This should help me get some traffic. Node.js and MongoDB are super fast. It doesn't even stutter when loading the site, across 500+ posts. Actually, I have no idea how many there are. Super fast.
Here's the code which pretty much finishes in -5 seconds
var db = require("../db");
this.tagCloud = [];
this.initialize = function(site, callback){
var self = this;
while (self.tagCloud.pop());
db.getPosts(site.db, {}, -1, -1, function(posts){
var tags = {};
posts.forEach(function(post){
if (post == null) return;
for (var i = 0; i < post.tags.length; i++){
if (tags[post.tags[i]] == null)
tags[post.tags[i]] = { tag: post.tags[i], count: 0 };
tags[post.tags[i]].count++;
}
});
for(var tag in tags){
if (tags[tag].count > 8) // arbitrary limit so we don't list like 200 tags with 1 post each
self.tagCloud.push(tags[tag]);
}
self.tagCloud.sort(function(a,b){ return b.count - a.count; });
callback();
});
}