going-flying.com gemini git repository
eb78798b21ee52c743d5eb2da587d1829099fa47 - Matthew Ernisse - 1595899429
potentially a new post?
diff --git a/.gitignore b/.gitignore index 6a437d3..f928b8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ users/mernisse/atom.xml +users/mernisse/*.gmi diff --git a/build/build.py b/build/build.py index e09752a..2a1b83c 100755 --- a/build/build.py +++ b/build/build.py @@ -1,10 +1,73 @@ #!/usr/bin/env python3 +import datetime +import jinja2 import os +import pytz +import re import sys from feedgen.feed import FeedGenerator +URLBASE = 'gemini://going-flying.com/~mernisse/' + +class GlogMetaReader(object): + meta_re = re.compile( + r'^[ ]{0,3}(?P<key>[A-Za-z0-9_-]+):\s*(?P<value>.*)' + ) + + def __init__(self, fn): + self.content = '' + self.fn = fn + self.meta = {} + + self.meta['link'] = URLBASE + os.path.basename(fn) + + with open(fn, encoding='utf-8') as fd: + content = fd.read() + + content = content.split('\n') + self._found = False + + if content[0] == '---': + self._found = True + + for line in content: + if self._found: + self.parseMeta(line) + continue + + self.content += line + '\n' + + def parseMeta(self, line): + if line.strip() == '': + self._found = False + return + + m = self.meta_re.match(line) + + if not m: + return + + k = m.group('key').lower().strip() + v = m.group('value').lower().strip() + + if k == 'date': + tzinfo = pytz.timezone('US/Eastern') + try: + d = datetime.datetime.strptime( + v, + '%m/%d/%Y %H:%M' + ) + d = d.replace(tzinfo=tzinfo) + v = d + + except Exception as e: + print(f'{self.fn} failed to parse date {e}') + pass + + self.meta[k] = v + class GeminiFeed(object): ''' Wrapper for FeedGenerator that contains defaults and whatnot.''' @@ -27,8 +90,9 @@ class GeminiFeed(object): def add(self, title, link, pubdate): entry = self.feed.add_entry() - entry.id = link - entry.updated = pubdate + entry.title(title) + entry.id(link) + entry.updated(pubdate) entry.link(href=link, rel='alternate') def write(self, fn): @@ -37,7 +101,54 @@ class GeminiFeed(object): if __name__ == '__main__': bdir = os.path.abspath(sys.argv[1]) - print(f'Starting build in {bdir}') + + adir = os.path.join(bdir, 'articles') + tdir = os.path.dirname(os.path.realpath(__file__)) feed = GeminiFeed() + + with open(os.path.join(tdir, 'template.txt'), encoding='utf-8') as fd: + article_template = fd.read() + + article_template = jinja2.Template( + article_template, + trim_blocks=True, + lstrip_blocks=True, + ) + + with open(os.path.join(tdir, 'index.txt'), encoding='utf-8') as fd: + index_template = fd.read() + + index_template = jinja2.Template( + index_template, + trim_blocks=True, + lstrip_blocks=True, + ) + + articles = [] + + for fn in os.listdir(adir): + article = GlogMetaReader(os.path.join(adir, fn)) + articles.append(article) + + feed.add( + article.meta['title'], + article.meta['link'], + article.meta['date'] + ) + + output = os.path.join(bdir, fn) + + with open(output, 'w', encoding='utf-8') as fd: + fd.write(article_template.render({ + 'article': article, + 'up': URLBASE + })) + + articles.sort(key=lambda a: a.meta['date'], reverse=True) + + output = os.path.join(bdir, 'index.gmi') + with open(output, 'w', encoding='utf-8') as fd: + fd.write(index_template.render({'articles': articles})) + feed.write(os.path.join(bdir, 'atom.xml')) diff --git a/build/index.txt b/build/index.txt new file mode 100644 index 0000000..4109cb4 --- /dev/null +++ b/build/index.txt @@ -0,0 +1,10 @@ +# Musings from a mildly misanthropic technologist + +=> /~mernisse/atom.xml There is an atom feed of posts here + +{% for article in articles %} +=> {{ article.meta.link }} [{{article.meta.date.strftime('%m/%d/%Y @%H:%M')}}]: {{ article.meta.title }} +{% endfor %} + + +🚀 © MMXX matt@going-flying.com diff --git a/build/template.txt b/build/template.txt new file mode 100644 index 0000000..6dcfc8a --- /dev/null +++ b/build/template.txt @@ -0,0 +1,7 @@ +# [{{article.meta.date.strftime('%m/%d/%Y @%H:%M')}}]: {{ article.meta.title }} + +{{article.content}} + +=> {{ up }} back + +🚀 © MMXX matt@going-flying.com diff --git a/users/mernisse/articles/00.gmi b/users/mernisse/articles/00.gmi new file mode 100644 index 0000000..fe6a55f --- /dev/null +++ b/users/mernisse/articles/00.gmi @@ -0,0 +1,46 @@ +--- +Title: A new start +Date: 07/27/2020 20:14 + +It was July 24th when I first read about the Gemini protocol. Someone posted +an article titled "Implement a Gemini Protocol Client Using Network.framework" +and my RSS feed reader dutifuly picked up on it. I'm not entirely sure why +I felt drawn to build things immediatly but for whatever reason I did. I +think I've written about 600 lines of Python just building silly things to +stick on my Gemini capsule here, created two bespoke Docker containers and +am most of the way done building some bespoke hardware to put online. + +=> https://shadowfacts.net/2020/gemini-network-framework/ + +## So what are my intentions? + +Well I'm still building things here before I think I can settle into just +posting things, but this already feels like a place where I can be a lot +more blunt than on my web site. The web site is pretty filtered, mostly +opinion-free technical content because when I left social media in the late +2000s I made the effort to keep the signal to 'noise' ratio of my personal +web site as low as possible. It turns out though that I have opinions, and +I sometimes feel like sharing them. I feel like I may be able to do that +here. + +I have a few more things I want to do with the site generator. Right now +I write these posts using nvi and then a git post-receive hook runs a +Python script that renders them into the .gmi files, the index and the +atom feed. The original files have some YAML metadata at the top and thanks +to my editor settings and muscle memory are generally wrapped manually around +column 79. Obviously the hand wrapping isn't compatible with the gemini +markup so one of the TODO items is to fix that. + +=> https://sites.google.com/a/bostic.com/keithbostic/vi/ + +There are also a few bugs with the HTML stripping in my Thoughts renderer +so I need to screw around with that some more too. + +=> /thoughts/ + +## And? + +So with the short ramble out of the way I'm going to commit this to my git +repository and then probably fix the several bugs in the rendering scripts +before it makes its way out into the world but I have to say I am honestly +looking forward to making more things for this little space. diff --git a/users/mernisse/index.gmi b/users/mernisse/index.gmi deleted file mode 100644 index 4b5fa63..0000000 --- a/users/mernisse/index.gmi +++ /dev/null @@ -1 +0,0 @@ -hello, world