From 8e26f1a9b21d3b218daa414a415e868dcf7c4681 Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Sun, 25 Feb 2024 18:31:08 -0600 Subject: [PATCH] Revert "add script to create gemini capsule" As cool as gemini seems... I'm not sure I have the energy/free time to target it right now. Maybe I'll revisit later. This reverts commit 1669e0ed0cca02aed9f02dea1f59b918e3d369f4. --- .gitignore | 3 +- process_capsule.py | 85 ---------------------------------------------- shell.nix | 11 ------ 3 files changed, 1 insertion(+), 98 deletions(-) delete mode 100644 process_capsule.py delete mode 100644 shell.nix diff --git a/.gitignore b/.gitignore index 3215f1d..d5f97c8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,4 @@ /public/ /resources/ /.env* -/capsule/ -/.certificates/ + diff --git a/process_capsule.py b/process_capsule.py deleted file mode 100644 index 73003fa..0000000 --- a/process_capsule.py +++ /dev/null @@ -1,85 +0,0 @@ -# Adapted from Will Webberley's work: -# https://wilw.dev/blog/2023/06/01/automatic-gemini-publishing/ -# https://git.wilw.dev/wilw/wilw.dev/src/branch/main/gemini/process_capsule.py - -import os, datetime, re -import frontmatter - -capsule_url = 'gemini://gmi.runtimeterror.dev' -web_url = 'https://runtimeterror.dev' -content_dir = 'content' -email = 'blog@runtimeterror.dev' -feed_url = 'https://runtimeterror.dev/feed.xml' -site_name = '[runtimeterror]' - -# Gemini-ify hyperlinks -def transform_links(content): - lines = content.splitlines() - pattern = re.compile(r'\[([^][]+)\]\(([^()]+)\)') - current_link_ref = 1 - new_lines = [] - for line_index, line in enumerate(lines): - if line.startswith('!['): continue - links_to_add = [] - if not line.startswith('=>'): - for link_index, match in enumerate(pattern.finditer(line)): - description, url = match.groups() - line = line.replace(f'({url})', f' [{current_link_ref}]').replace(f'[{description}]', description) - # if URL self-references website, handle differently: - if not url.startswith('http') or url.startswith(web_url): - if web_url in url: url = url.replace(web_url, '') - url = capsule_url + '/' + url.replace('/', ' ').strip().replace(' ', '-') + '.gmi' - links_to_add.append(f'=> {url} {current_link_ref}') - current_link_ref += 1 - new_lines.append(line) - for link in links_to_add: - new_lines.append(link) - return '\n'.join(new_lines) - -# Create new directories -needed_directories = ['capsule'] -for dir in needed_directories: - if not os.path.exists(dir): - os.makedirs(dir) - -# Generate blog posts -logs = [] -for dirpath, dirnames, filenames in os.walk(content_dir): - if 'index.md' in filenames: - post = frontmatter.load(os.path.join(dirpath, 'index.md')) - date = post['date'] if isinstance(post['date'], datetime.date) else datetime.datetime.strptime(post['date'].split('T')[0], '%Y-%m-%d') - content = transform_links(post.content) - new_content = ''' -=> {} 🏡 Home - -# {} -## Posted on {} - -{} - -=> mailto:{} Reply via email -=> {} Back to home - '''.format(capsule_url, post['title'], date.strftime('%Y-%m-%d'), content, email, capsule_url) - new_file_name = f'{os.path.basename(dirpath)}.gmi' - logs.append({'file': new_file_name, 'title': post['title'], 'date': date}) - with open(f'capsule/{new_file_name}', 'w') as gem_file: - gem_file.write(new_content) - -# Generate blog index -logs.sort(key=lambda entry: entry['date'].strftime('%Y-%m-%d'), reverse=True) -log_index_content = ''' -=> {} 🏡 Home - -# {} - -=> {} 📲 Subscribe via RSS - -{} - -=> {} 🏡 Home -'''.format(capsule_url, site_name, feed_url, - '\n'.join(['=> {} {} - {}'.format(l['file'], l['date'].strftime('%Y-%m-%d'), l['title']) for l in logs]), - capsule_url) -gem_index_file = open(f'capsule/index.gmi', 'w') -gem_index_file.write(log_index_content) - diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 3140b63..0000000 --- a/shell.nix +++ /dev/null @@ -1,11 +0,0 @@ -let - pkgs = import {}; -in pkgs.mkShell { - packages = with pkgs; [ - agate - hugo - (python3.withPackages (python-pkgs: [ - python-pkgs.python-frontmatter - ])) - ]; -}