]> git.ipfire.org Git - ipfire.org.git/commitdiff
blog: Add RSS feed to the blog
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Jul 2018 17:24:47 +0000 (18:24 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Jul 2018 17:29:48 +0000 (18:29 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/templates/blog/feed.xml [new file with mode: 0644]
src/templates/feeds/base.xml [deleted file]
src/templates/feeds/news.xml [deleted file]
src/templates/feeds/planet.xml [deleted file]
src/web/__init__.py
src/web/blog.py

index 6e806e7aee5fa7016ae0a6ec9007b22b28ac933e..8761a28316018bbc7f9c9d72901a30387e762e01 100644 (file)
@@ -110,6 +110,7 @@ templatesdir = $(datadir)/templates
 templates_blog_DATA = \
        src/templates/blog/author.html \
        src/templates/blog/base.html \
+       src/templates/blog/feed.xml \
        src/templates/blog/index.html \
        src/templates/blog/post.html \
        src/templates/blog/search-results.html
diff --git a/src/templates/blog/feed.xml b/src/templates/blog/feed.xml
new file mode 100644 (file)
index 0000000..f159bc2
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<rss version="2.0"
+               xmlns:content="http://purl.org/rss/1.0/modules/content/"
+               xmlns:atom="http://www.w3.org/2005/Atom"
+               xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">
+       <channel>
+               <title>IPFire Blog</title>
+               <atom:link href="https://blog.ipfire.org/feed.xml" rel="self" type="application/rss+xml" />
+               <link>https://blog.ipfire.org</link>
+               <description>The official blog of the IPFire Project</description>
+               <lastBuildDate>{{ now }}</lastBuildDate>
+               <language>en-GB</language>
+               <sy:updatePeriod>hourly</sy:updatePeriod>
+               <sy:updateFrequency>1</sy:updateFrequency>
+
+               <image>
+                       <url>https://www.ipfire.org{{ static_url("img/tux/ipfire_tux_32x32.png") }}</url>
+                       <title>IPFire Blog</title>
+                       <link>https://blog.ipfire.org</link>
+                       <width>32</width>
+                       <height>32</height>
+               </image>
+
+               <atom:link rel="payment" title="Donate!" href="https://www.ipfire.org/donate" type="text/html" />
+
+               {% for post in posts %}
+                       <item>
+                               <title>{{ post.title }}</title>
+                               <link>https://blog.ipfire.org/post/{{ post.slug }}</link>
+                               <author>{{ post.author.email }} ({{ post.author.name }})</author>
+                               <pubDate>{{ post.published.strftime("%a, %d %b %Y %H:%M:%S +0200") }}</pubDate>
+                               <guid isPermaLink="false"></guid>
+                               <description><![CDATA[{% raw post.text %}]]></description>
+                       </item>
+               {% end %}
+       </channel>
+</rss>
diff --git a/src/templates/feeds/base.xml b/src/templates/feeds/base.xml
deleted file mode 100644 (file)
index ee74fa0..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<rss version="2.0">
-       <channel>
-               <title>{% block title %}{% end block %}</title>
-               <link>{% block url %}{% end block %}</link>
-               <description>{% block description %}{% end block %}</description>
-               <language>en_GB</language>
-               <copyright>{% block copyright %}IPFire Team{% end block %}</copyright>
-               <pubDate>Thu, 8 Nov 2007 00:00:00 +0200</pubDate>
-               {% for item in items %}
-                       <item>
-                               <title>{{ item.title }}</title>
-                               <link>{{ item.url }}</link>
-                               <author>{{ item.author.email }} ({{ item.author.name }})</author>
-                               <guid>{{ item.url }}</guid>
-                               <pubDate>{{ item.published.strftime("%a, %d %b %Y %H:%M:%S +0200") }}</pubDate>
-                               <description>
-                                       <![CDATA[{% raw item.markup %}]]>
-                               </description>
-                       </item>
-               {% end %}
-       </channel>
-</rss>
diff --git a/src/templates/feeds/news.xml b/src/templates/feeds/news.xml
deleted file mode 100644 (file)
index 1b3a860..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-{% extends "base.xml" %}
-
-{% block title %}IPFire.org - News{% end block%}
-{% block url %}http://www.ipfire.org/{% end block %}
-{% block description %}IPFire News Feed{% end block %}
diff --git a/src/templates/feeds/planet.xml b/src/templates/feeds/planet.xml
deleted file mode 100644 (file)
index e42aea9..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-{% extends "base.xml" %}
-
-{% block title %}planet.ipfire.org{% end block%}
-{% block url %}http://planet.ipfire.org/{% end block %}
-{% block description %}IPFire Planet Feed{% end block %}
index bf42bdf26220191eae33d82f6180f4775be404a3..12fc732033ba050c76f0c17f6fba85d909251f88 100644 (file)
@@ -94,7 +94,7 @@ class Application(tornado.web.Application):
                        (r"/donation", tornado.web.RedirectHandler, { "url" : "/donate" }),
 
                        # RSS feed
-                       (r"/news.rss", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/feed.rss" }),
+                       (r"/news.rss", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/feed.xml" }),
 
                        # Redirect news articles to blog
                        (r"/news/(.*)", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/posts/{1}" }),
@@ -120,6 +120,9 @@ class Application(tornado.web.Application):
                        (r"/authors/(\w+)", blog.AuthorHandler),
                        (r"/post/(.*)", blog.PostHandler),
                        (r"/search", blog.SearchHandler),
+
+                       # RSS Feed
+                       (r"/feed.xml", blog.FeedHandler),
                ])
 
                # downloads.ipfire.org
@@ -150,9 +153,9 @@ class Application(tornado.web.Application):
                        (r"/user/([a-z0-9_-]+)", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/authors/{1}" }),
 
                        # RSS
-                       (r"/rss", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/feed.rss" }),
+                       (r"/rss", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/feed.xml" }),
                        (r"/user/([a-z0-9_-]+)/rss", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/authors/{1}.rss" }),
-                       (r"/news.rss", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/feed.rss" }),
+                       (r"/news.rss", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/feed.xml" }),
                ])
 
                # fireinfo.ipfire.org
index 2ff59b5e3ef74fac76279b60a9ea57f059989228..635c224d44337890c2901278267c2f48830991e0 100644 (file)
@@ -1,5 +1,6 @@
 #!/usr/bin/python
 
+import email.utils
 import tornado.web
 
 import handlers_base as base
@@ -27,6 +28,29 @@ class AuthorHandler(base.BaseHandler):
                self.render("blog/author.html", author=author, posts=posts)
 
 
+class FeedHandler(base.BaseHandler):
+       def get(self):
+               cache_key = "%s-%s" % (self.request.host, self.request.path)
+
+               # Get feed from cache if possible
+               feed = self.memcached.get(cache_key)
+               if not feed:
+                       posts = self.planet.get_entries(limit=50)
+
+                       # Render the feed
+                       feed = self.render_string("blog/feed.xml", posts=posts,
+                               now=email.utils.formatdate())
+
+                       # Store in cache for 5min
+                       self.memcached.set(cache_key, feed, 300)
+
+               # Set correct content type
+               self.set_header("Content-Type", "application/rss+xml")
+
+               # Deliver content
+               self.finish(feed)
+
+
 class PostHandler(base.BaseHandler):
        def get(self, slug):
                entry = self.planet.get_entry_by_slug(slug)