add archives route/view

This commit is contained in:
Gered 2013-05-26 18:45:15 -04:00
parent 475f3e397d
commit 4286eca04f
4 changed files with 39 additions and 0 deletions

View file

@ -82,6 +82,14 @@
(= minutes 1) "1 minute ago"
:else "just now"))))
(defn ->month-day-str
"Returns a date string in the format 'MMM d' from the given date object or
string timestamp"
[date]
(if (string? date)
(->month-day-str (clj-time.local/to-local-date-time date))
(clj-time.format/unparse (clj-time.format/formatter "MMM d") date)))
(defn ->nicer-month-year-str
"Given a date in 'MM-yyyy' format (numeric month), returns the same date in
'MMM yyyy' format (name of month)"

View file

@ -55,6 +55,10 @@
"posts/listbytag.html" {:posts (posts/list-posts-by-tag (auth/logged-in?) tag)
:tag tag}))
(defn list-archive []
(layout/render
"posts/listarchive.html" {:months (posts/list-posts-archive (auth/logged-in?))}))
(defn show-post-page [year month day slug]
(let [date (str year "-" month "-" day)
post (posts/get-post-by-date-slug date slug)]
@ -117,6 +121,7 @@
[year month day slug]
(show-post-page year month day slug))
(GET "/tag/:tag" [tag] (list-by-tag tag))
(GET "/archive" [] (list-archive))
(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,23 @@
{% extends "blarg/views/templates/base.html" %}
{% block content %}
<div class="page-header">
<h2>Archive</h2>
</div>
<div>
{% for month in months %}
{% for post in month %}
{% if forloop.first %}
<h3>{{post.mmyyyy}}</h3>
{% endif %}
<div class="row">
<div class="span2 muted text-right"><time title="{{post.created_at|to_fulltime}}">{{post.created_at|to_month-day}}</time></div>
<div class="span9"><a href="{{context}}{{post|post-url}}">{{post.title}}</a></div>
</div>
{% endfor %}
{% endfor %}
</div>
{% endblock %}

View file

@ -25,5 +25,8 @@
(deftemplatefilter "to_relative" [node body arg]
(->relative-timestamp body))
(deftemplatefilter "to_month-day" [node body arg]
(->month-day-str body))
(deftemplatefilter "to_fulltime" [node body arg]
(clj-time.local/format-local-time body :rfc822))