Add RSS and Atom feed for the blog
This commit is contained in:
parent
2b18d44281
commit
9139ad1aa2
3 changed files with 49 additions and 0 deletions
45
blog/feeds.py
Normal file
45
blog/feeds.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
from datetime import datetime, time
|
||||||
|
|
||||||
|
from django.contrib.syndication.views import Feed
|
||||||
|
from django.http import Http404
|
||||||
|
|
||||||
|
from .models import BlogPage, BlogIndexPage
|
||||||
|
from django.utils.feedgenerator import Atom1Feed
|
||||||
|
|
||||||
|
|
||||||
|
class RssBlogFeed(Feed):
|
||||||
|
title = "Konstantin's Blog Feed"
|
||||||
|
description = "A blog on independent software development, Swift, Elixir and more..."
|
||||||
|
|
||||||
|
def link(self):
|
||||||
|
root = BlogIndexPage.objects.live().public().first()
|
||||||
|
if not root:
|
||||||
|
raise Http404
|
||||||
|
return root.full_url
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
return BlogPage.objects.live().public().order_by("-first_published_at")
|
||||||
|
|
||||||
|
def item_title(self, item):
|
||||||
|
return item.title
|
||||||
|
|
||||||
|
def item_description(self, item):
|
||||||
|
return item.intro
|
||||||
|
|
||||||
|
def item_link(self, item):
|
||||||
|
return item.full_url
|
||||||
|
|
||||||
|
def item_pubdate(self, item):
|
||||||
|
return datetime.combine(item.date, time())
|
||||||
|
|
||||||
|
def item_author_name(self, item):
|
||||||
|
author = item.authors.first()
|
||||||
|
if not author:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return author.name
|
||||||
|
|
||||||
|
|
||||||
|
class AtomBlogFeed(RssBlogFeed):
|
||||||
|
feed_type = Atom1Feed
|
||||||
|
subtitle = RssBlogFeed.description
|
|
@ -35,6 +35,8 @@
|
||||||
{# Global stylesheets #}
|
{# Global stylesheets #}
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'css/iamkonstantin_web.css' %}">
|
<link rel="stylesheet" type="text/css" href="{% static 'css/iamkonstantin_web.css' %}">
|
||||||
|
|
||||||
|
<link title="Konstantin's Blog" type="application/atom+xml" rel="alternate" href="{% url 'blog_feed' %}">
|
||||||
|
|
||||||
{% block extra_css %}
|
{% block extra_css %}
|
||||||
{# Override this in templates to add extra stylesheets #}
|
{# Override this in templates to add extra stylesheets #}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -6,6 +6,7 @@ from wagtail.admin import urls as wagtailadmin_urls
|
||||||
from wagtail import urls as wagtail_urls
|
from wagtail import urls as wagtail_urls
|
||||||
from wagtail.documents import urls as wagtaildocs_urls
|
from wagtail.documents import urls as wagtaildocs_urls
|
||||||
|
|
||||||
|
from blog.feeds import RssBlogFeed
|
||||||
from search import views as search_views
|
from search import views as search_views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
@ -13,6 +14,7 @@ urlpatterns = [
|
||||||
path("admin/", include(wagtailadmin_urls)),
|
path("admin/", include(wagtailadmin_urls)),
|
||||||
path("documents/", include(wagtaildocs_urls)),
|
path("documents/", include(wagtaildocs_urls)),
|
||||||
path("search/", search_views.search, name="search"),
|
path("search/", search_views.search, name="search"),
|
||||||
|
path("blog/feed/", RssBlogFeed(), name="blog_feed"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue