diff --git a/lib/blogs.js b/lib/blogs.js index 3a4b889..ebc3f8d 100644 --- a/lib/blogs.js +++ b/lib/blogs.js @@ -3,7 +3,7 @@ var path = require('path'); var glob = require('glob'); var marked = require('marked'); var moment = require('moment'); -var _ = require('underscore'); +var _ = require('lodash'); var blogs = []; @@ -63,9 +63,15 @@ var find = function(url) { return url ? _.findWhere(blogs, { url: url }) : blogs; }; +var findByTag = function(tag) { + _reinit(); + return _.where(blogs, { tags: [tag] }); +}; + module.exports = { init: init, - find: find + find: find, + findByTag: findByTag }; init(); diff --git a/package.json b/package.json index 529c472..c60c299 100644 --- a/package.json +++ b/package.json @@ -18,14 +18,13 @@ "express": "~3.2.5", "mustachex": "0.0.2", "glob": "~3.2.1", - "underscore": "~1.4.4", "marked": "~0.2.9", - "moment": "~2.0.0" + "moment": "~2.0.0", + "lodash": "~2.4.1" }, "engines": { "node": "0.10.x", "npm": "1.2.x" }, - "scripts": { - } + "scripts": {} } diff --git a/routes/index.js b/routes/index.js index c961199..424a82a 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,6 +1,6 @@ var config = require('../config'); var blogs = require('../lib/blogs'); -var _ = require('underscore'); +var _ = require('lodash'); var routes = function(app) { app.get('/', function(req, res) { @@ -13,6 +13,16 @@ var routes = function(app) { res.render('all', { blogs: all, config: config }); }); + app.get('/tag/:tag', function(req, res, next){ + var tagged = blogs.findByTag(req.param('tag')) + + if (tagged.length === 0) { + return res.render('help', { config: config }); + } + res.render('all', { blogs: tagged, config: config }); + }); + + app.get('/posts/:url', function(req, res, next) { var blog = blogs.find(req.param('url')); diff --git a/views/all.html b/views/all.html index ff66d49..8923661 100644 --- a/views/all.html +++ b/views/all.html @@ -13,7 +13,7 @@

{{relativeDate}}

{{#tags}} -
{{.}}
+
{{.}}
{{/tags}} diff --git a/views/post.html b/views/post.html index deec30e..018a6b4 100644 --- a/views/post.html +++ b/views/post.html @@ -11,7 +11,7 @@

{{blog.relativeDate}}

{{#blog.tags}} -
{{.}}
+
{{.}}
{{/blog.tags}}