add route/view for viewing posts by tag

This commit is contained in:
Gered 2013-05-26 17:30:40 -04:00
parent 2a36c293df
commit e308c35620
2 changed files with 22 additions and 0 deletions

View file

@ -50,6 +50,11 @@
:atfirstpage (= currentpage 0)
:inlist true})))
(defn list-by-tag [tag]
(layout/render
"posts/listbytag.html" {:posts (posts/list-posts-by-tag (auth/logged-in?) tag)
:tag tag}))
(defn show-post-page [year month day slug]
(let [date (str year "-" month "-" day)
post (posts/get-post-by-date-slug date slug)]
@ -111,6 +116,7 @@
["/:year/:month/:day/:slug" :year #"[0-9]{4}" :month #"[0-9]{1,2}" :day #"[0-9]{1,2}" :slug #"(.*)"]
[year month day slug]
(show-post-page year month day slug))
(GET "/tag/:tag" [tag] (list-by-tag tag))
(restricted GET "/newpost" [] (new-post-page))
(restricted POST "/newpost" [title tags body] (handle-new-post title tags body))
(restricted GET "/editpost/:id" [id] (edit-post-page id))

View file

@ -0,0 +1,16 @@
{% extends "blarg/views/templates/base.html" %}
{% block content %}
<div class="page-header">
<h2>Posts tagged with: {{tag}}</h2>
</div>
{% for post in posts %}
<div class="row table-hover">
<div class="span2 muted text-right"><time title="{{post.created_at|to_fulltime}}">{{post.created_at|to_relative}}</time></div>
<div class="span9"><a href="{{context}}{{post|post-url}}">{{post.title}}</a></div>
</div>
{% endfor %}
{% endblock %}