💾 Archived View for mozz.us › journal › 2020-02-09.gmi captured on 2021-12-03 at 14:04:38. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2020-09-24)
-=-=-=-=-=-=-
Published 2020-02-09
I'm going to start calling my gemini /journal directory a "gemlog" since that appears to be the preferred nomenclature.
In related news, I wrote a little static index generator to spruce up my /journal page. I wanted the index page to look a bit nicer than a list of bare filenames. Currently all the script does is parse the title and date from the first two lines of each file, and then sort the entries by date. I'm trying really hard not to over-engineer this upfront, and instead let it grow organically based on how I actually end up using it.
Eventually I would like to add this script to the jetforce github repo as an example. For now, here it is in all of its glory.
---
#!/usr/bin/env python3 """ A static gemlog (gemini blog) generator for jetforce servers. This script will scan through all of the text files in the specified gemlog directory. A formatted index of all log entries will be generated and written to index.gmi. Text files corresponding to gemlog entries MUST be formatted as follows: `` Title of Entry 2020-02-18 Content begins here... `` Links can be included in .gmi entries using the standard gemini format (=>link). """ import argparse import datetime import pathlib HEADER = """\ _ ___ ___ _____| |___ ___ | . | -_| | | . | . | |_ |___|_|_|_|_|___|_ | |___| M O Z Z . U S |___| """ FOOTER = """ (fin) """ def main(args): entries = [] for filepath in args.path.iterdir(): if filepath.name == 'index.gmi': continue try: with filepath.open() as fp: entries.append( { 'title': fp.readline().strip(), 'date': fp.readline().strip(), 'filename': filepath.name } ) except OSError: pass with (args.path / "index.gmi").open('w') as fp: fp.write(HEADER) fp.write(f'Last Updated {datetime.datetime.now():%Y-%m-%d}\n\n') for entry in sorted(entries, key=lambda e: e['date'], reverse=True): fp.write('=>{filename} [{date}] {title}\n'.format(**entry)) fp.write(FOOTER) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('path', type=pathlib.Path) args = parser.parse_args() main(args)