diff --git a/blog/templates/blog/feed.xml b/blog/templates/blog/feed.xml new file mode 100644 index 0000000..059f671 --- /dev/null +++ b/blog/templates/blog/feed.xml @@ -0,0 +1,35 @@ + +{% load static from staticfiles %} +{% load get_post_link from blog_link %} + + + Gergely Polonkai + Gergely Polonkai’s Blog + {{ site_url }} +{% comment %} +The element defines the last publication date for the content in the RSS feed. +The element defines the last-modified date of the content of the feed. + +TODO: Incorporate a modified_at field in the blog. These fields must depend on them. +{% endcomment %} + {{ last_build_date }} + {{ last_build_date }} + 7200 + en + + Gergely Polonkai + {{ profile_pic }} + {{ site_url }} + +{% for post in posts %} + + <![CDATA[ {{ post.title }} ]]> + {% get_post_link post %} + {% get_post_link post %}#comments + {{ post.created_at_rss }} + + {% get_post_link post %} + +{% endfor %} + + diff --git a/blog/views.py b/blog/views.py index 6e85059..9ce7e27 100644 --- a/blog/views.py +++ b/blog/views.py @@ -1,6 +1,10 @@ from django.shortcuts import render, get_object_or_404 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from blog.models import Post, CodeChunk +from django.core.urlresolvers import reverse +import datetime +import pytz +from django.templatetags.static import static def mainpage(request): last_posts = Post.objects.filter(draft = False).order_by('-created_at')[:5] @@ -96,5 +100,21 @@ def codechunk(request, language, slug): return render(request, 'blog/code-chunk.html', {'codechunk': chunk}) def feed(request): - return render(request, 'blog/feed.xml', {}) + latest_post = Post.objects.filter(draft = False).order_by('-created_at')[0:1] + + if not latest_post: + latest_date = datetime.datetime(1983, 3, 7, 11, 54, 45, 0, pytz.timezone('Europe/Budapest')) + else: + latest_date = latest_post[0].created_at + + posts = Post.objects.order_by('-created_at')[:10] + + return render(request, 'blog/feed.xml', { + 'site_url': request.build_absolute_uri(reverse('home')), + 'profile_pic': request.build_absolute_uri(static('images/profile.png')), + 'last_build_date': latest_date.strftime('%a, %d %b %Y %T %z'), + 'posts': posts, + }, + content_type = 'application/xml' + ) diff --git a/gergelypolonkaiweb/templates/front_base.html b/gergelypolonkaiweb/templates/front_base.html index 7e26cd6..69eb88f 100644 --- a/gergelypolonkaiweb/templates/front_base.html +++ b/gergelypolonkaiweb/templates/front_base.html @@ -15,7 +15,7 @@ {% endblock %} {% endcompress %} - +