Commits

David Chambers committed f1f2215

Added `posts` and `archives` to `context_defaults`. Added category and tag templates.

Comments (0)

Files changed (5)

templates/category.dhtml

+{% extends 'base.dhtml' %}
+{% load mango_extras %}
+{% block content %}
+			<h1>{{ name|capfirst }}</h1>
+	{% for post in category %}{% include 'excerpt.dhtml' %}{% empty %}
+			<p>This category is currently empty.</p>
+	{% endfor %}
+{% endblock %}

templates/excerpt.dhtml

+{% load mango_extras %}
+			<article>
+				<header>
+					<h2><a href="{{ post.canon_urls.rel }}">{{ post.meta.title|safe }}</a></h2>
+					<time datetime="{{ post.meta.datetime|datetime }}">{{ post.meta.datetime|display_date }}</time>
+				</header>
+				{{ post.excerpt|safe }}
+			</article>

templates/index.dhtml

 {% load mango_extras %}
 {% block header_title %}<h1><a href="/">{{ settings.SITE_TITLE }}</a></h1>{% endblock %}
 {% block content %}
-	{% for post in posts %}{% if forloop.counter <= 5 %}
-			<article>
-				<header>
-					<h2><a href="{{ post.canon_urls.rel }}">{{ post.meta.title|safe }}</a></h2>
-					<time datetime="{{ post.meta.datetime|datetime }}">{{ post.meta.datetime|display_date }}</time>
-				</header>
-				{{ post.excerpt|safe }}
-			</article>
-	{% else %}{% if forloop.last %}
+	{% for post in posts %}{% if forloop.counter <= 5 %}{% include 'excerpt.dhtml' %}{% else %}{% if forloop.last %}
 			<h2>Want more?</h2>
 			<p>Check out the <a href="{% url mango.views.archives %}">archives</a>.</p>
 	{% endif %}{% endif %}{% empty %}

templates/tag.dhtml

+{% extends 'base.dhtml' %}
+{% load mango_extras %}
+{% block content %}
+			<h1>Posts tagged "{{ tag }}"</h1>
+	{% for post in tagged %}{% include 'excerpt.dhtml' %}{% empty %}
+			<p>There are currently no posts tagged "{{ tag }}".</p>
+	{% endfor %}
+{% endblock %}
     path_to_css, css = settings.__dict__.get('CSS', (None, []))
     path_to_js, js = settings.__dict__.get('JS', (None, []))
     return {
-        'request': request,
+        'archives': utils.archives(),
+        'posts': utils.posts(),
         'settings': settings,
         'stylesheets': [dict(media=media, href=path_to_css.lstrip('.')+filename) for media, stylesheets in css for filename in stylesheets],
         'scripts': [dict(src=path_to_js.lstrip('.')+filename) for filename in js],
     }
 
 def index(request):
-    return render_to_response('index.dhtml', dict({
-                'posts': utils.posts(),
-            }, **context_defaults(request)))
+    return render_to_response('index.dhtml', context_defaults(request))
 
 def archives(request):
-    return render_to_response('archives.dhtml', dict({'archives': utils.archives()}, **context_defaults(request)))
+    return render_to_response('archives.dhtml', context_defaults(request))
 
 def tags(request):
     tags = {}
 
 def tagged_as(request, tag):
     tag = slugify(tag)
-    posts = [p for p in utils.posts() if tag in [slugify(t) for t in p['meta'].get('tags', [])]]
-    return render_to_response('index.dhtml', dict({'posts': posts}, **context_defaults(request)))
+    return render_to_response('tag.dhtml', dict({
+                'tag': tag,
+                'tagged': [p for p in utils.posts() if tag in [slugify(t) for t in p['meta'].get('tags', [])]],
+            }, **context_defaults(request)))
 
 #TODO - this name should be changed as it now is also an index page, should this be combined with the index post?
 def post(request, path, view_source=False):
     if os.path.isdir(filepath):
         #TODO - if view_source is true what do we do here?
         #TODO - caching
-        html = render_to_response('index.dhtml', dict({
-            'posts': utils.posts(filepath),
+        match = re.match(RE['alias=>canon'], os.path.split(filepath)[1])
+        html = render_to_response('category.dhtml', dict({
+            'name': match.group('canon'),
+            'category': utils.posts(filepath),
         }, **context_defaults(request)))
         return HttpResponse(html)