added rss
This commit is contained in:
parent
e56ef23c2d
commit
d779e5e0a8
@ -1 +1,2 @@
|
||||
Flask-Markdown==0.3
|
||||
Flask-Markdown==0.3
|
||||
rfeed==1.1.1
|
@ -1,6 +1,8 @@
|
||||
import datetime
|
||||
import html
|
||||
|
||||
from flask import render_template, request, flash, redirect, url_for
|
||||
import rfeed
|
||||
from flask import render_template, request, flash, redirect, url_for, Response
|
||||
|
||||
from webapp.routes import *
|
||||
from oshipka.webapp import app
|
||||
@ -53,3 +55,28 @@ def blog_post_filename(filename):
|
||||
flash("Blog post doesn't exist")
|
||||
return redirect(url_for('index'))
|
||||
return render_template("blog_post/get.html", instance=blog_post)
|
||||
|
||||
|
||||
@app.route('/rss.xml')
|
||||
def rss():
|
||||
feed_items = []
|
||||
for blog_post in BlogPost.query.order_by(BlogPost.created_dt.desc()).all():
|
||||
d = blog_post.created_dt
|
||||
pub_date = datetime.datetime(int(d[0:4]), int(d[4:6]), int(d[6:8]))
|
||||
item = rfeed.Item(
|
||||
title=blog_post.title,
|
||||
link="https://blog.pi2.dev/blog_post/{}".format(blog_post.filename),
|
||||
description="{}...".format(blog_post.body[:300]),
|
||||
author="Daniel",
|
||||
guid=rfeed.Guid("https://blog.pi2.dev/blog_post/{}".format(blog_post.filename)),
|
||||
pubDate=pub_date)
|
||||
feed_items.append(item)
|
||||
|
||||
feed = rfeed.Feed(
|
||||
title="Pi2-Blog posts",
|
||||
link="https://blog.pi2.dev/rss.xml",
|
||||
description="Pisquared Blog - Recently updated posts",
|
||||
language="en-US",
|
||||
lastBuildDate=datetime.datetime.now(),
|
||||
items=feed_items)
|
||||
return Response(feed.rss(), mimetype='text/xml')
|
||||
|
@ -11,6 +11,7 @@
|
||||
href="{{ url_for('static', filename='favicons/favicon-96x96.png') }}">
|
||||
<link rel="icon" type="image/png" sizes="16x16"
|
||||
href="{{ url_for('static', filename='favicons/favicon-16x16.png') }}">
|
||||
<link rel="alternate" type="application/rss+xml" title="PiSquared Blog Updates" href="https://blog.pi2.dev/rss.xml" />
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: "Open Sans", Arial, sans-serif;
|
||||
|
@ -1,3 +1,4 @@
|
||||
<a href="{{ url_for('home') }}">{{ _("PiSquared Blog") }}</a> |
|
||||
<a href="{{ url_for('index') }}">{{ _("Index") }}</a> |
|
||||
<a href="{{ url_for('rss') }}">{{ _("RSS") }}</a> |
|
||||
<a href="{{ url_for('aboutme') }}">{{ _("About Me") }}</a>
|
Loading…
Reference in New Issue
Block a user