shii.moe

Source for `shii.moe' website.
git clone git://git.knutsen.co/shii.moe
Log | Files | Refs | README | LICENSE

commit 8e9242475efbbccbcc64993a3d5cd18f3f05447f
parent 93cc494b84510e02b084b6270cb1e7f459971142
Author: Demonstrandum <samuel@knutsen.co>
Date:   Mon, 15 Aug 2022 22:34:36 +0100

Added RSS/Atom feed at /rss.xml.

Serves an Atom blog feed on /rss.xml or /atom.xml.

Diffstat:
Mblog/wa-state.md | 1+
Mshiimoe/__init__.py | 30+++++++++++++++++++++++++++---
Mshiimoe/templates/blogindex.html | 2+-
Ashiimoe/templates/rss.xml | 34++++++++++++++++++++++++++++++++++
4 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/blog/wa-state.md b/blog/wa-state.md @@ -1,6 +1,7 @@ --- title: (WIP) A Brief History of the Wa people (佤族) published: 2022-03-17 18:45:00 +updated: 2022-08-15 22:05:28 --- *this article is a work in progress* diff --git a/shiimoe/__init__.py b/shiimoe/__init__.py @@ -55,16 +55,25 @@ def get_blog_posts(): posts = [] for file in os.listdir(BLOG_PATH): slug = file[:-3] + + content = None meta = None with open(f"{BLOG_PATH}/{file}", 'r') as f: - md.convert(f.read()) + content = md.convert(f.read()) meta = md.Meta + + published = meta['published'] + updated = meta.get('updated', published) posts.append({ 'slug': slug, 'title': meta['title'], + 'content': content, 'published': meta['published'], - 'date': datetime.strftime(meta['published'], '%Y-%m-%d'), - 'datetime': meta['published'].isoformat() + 'updated': updated, + 'date': datetime.strftime(updated, '%Y-%m-%d'), + 'datetime': updated.isoformat(), + 'pubdate': datetime.strftime(published, '%Y-%m-%d'), + 'pubdatetime': published.isoformat(), }) posts.sort(key = lambda post: post['published'], reverse=True) return tuple(posts) @@ -116,6 +125,9 @@ STATIC_TEMPLATES = { ('blogindex.html', frozen({ 'posts': STATIC_BLOG_POSTS })): static_template('blogindex.html', posts=STATIC_BLOG_POSTS), + ('rss.xml', frozen({ + 'posts': STATIC_BLOG_POSTS + })): static_template('rss.xml', posts=STATIC_BLOG_POSTS), } for blogpost in os.listdir(BLOG_PATH): @@ -185,6 +197,18 @@ def render_guestbook(**kw): def guestbook(): return render_guestbook() +@app.route('/rss.xml') +@app.route('/rss') +@app.route('/atom.xml') +@app.route('/atom') +@app.route('/index.xml') +@app.route('/blog.xml') +@app.route('/posts.xml') +@app.route('/blog/index.xml') +def rssblogposts(): + posts = get_blog_posts() + return template('rss.xml', posts=posts) + @app.route('/blog') @app.route('/blog/index.html') def blogindex(): diff --git a/shiimoe/templates/blogindex.html b/shiimoe/templates/blogindex.html @@ -37,7 +37,7 @@ <a href="/blog/{{ post['slug'] }}"> <span class="title">{{ post['title'] }}</span> <span class="published"> - (<time datetime="{{ post['datetime'] }}">{{ post['date'] }}</time>) + (<time datetime="{{ post['pubdatetime'] }}">{{ post['pubdate'] }}</time>) </span> </a> </li> diff --git a/shiimoe/templates/rss.xml b/shiimoe/templates/rss.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> + +<feed xmlns="http://www.w3.org/2005/Atom"> + <title>Shiimoe Blog Feed</title> + <subtitle>Blog posts on shii.moe.</subtitle> + {% block author %} + <author> + <name>Shimo (Shiimoe)</name> + <email>me@shii.moe</email> + <uri>https://shii.moe/</uri> + </author> + {% endblock %} + <category term="blog"/> + <link href="https://shii.moe/rss.xml" rel="self" /> + <link href="http://shii.moe/" /> + <id>shii.moe</id> + <updated>{{ posts[0]['datetime'] }}Z</updated> + + {% for post in posts %} + <entry> + <id>shii.moe/blog/{{ post['slug'] }}</id> + <title>{{ post['title'] }}</title> + <published>{{ post['pubdatetime'] }}Z</published> + <updated>{{ post['datetime'] }}Z</updated> + {{ self.author() }} + <link rel="alternate" href="/blog/{{ post['slug'] }}"/> + <category term="blog"/> + <content> + <![CDATA[{{ post['content'] | safe }}]]> + </content> + </entry> + {% endfor %} +</feed> +