all repos — site @ d0af42936f5ac055deafaa80703bfbbce060c09c

source for my site, found at icyphox.sh

rss.py (view raw)

 1#!/usr/bin/env python3
 2# generate an rss item
 3
 4import html
 5from markdown2 import markdown_path
 6import sys
 7import datetime
 8import os
 9
10try:
11    mdfile = sys.argv[1]
12except IndexError:
13    print('error: specify path to markdown file')
14    sys.exit(-1)
15url =  os.path.splitext(mdfile)[0]
16rendered = markdown_path(mdfile, extras=['metadata',
17        'fenced-code-blocks', 'header-ids', 'footnotes', 'smarty-pants'])
18meta = rendered.metadata
19esc = html.escape(rendered)
20
21# time stuff
22dt = datetime.datetime.strptime(meta['date'], '%Y-%m-%d').date()
23rfc822 = dt.strftime("%a, %d %b %Y %H:%M:%S %z") + '+0000'
24
25item = f"""<item>
26      <title>{meta['title']}</title>
27      <link>https://icyphox.sh/blog/{url}</link>
28      <description>{esc}</description>
29      <pubDate>{rfc822}</pubDate>
30      <guid>https://icyphox.sh/blog/{url}/</guid>
31</item>
32"""
33
34print(item)