add support for local urls in gemini when text posts are present

This commit is contained in:
nebula 2025-04-03 05:51:37 +00:00
parent 6608577e85
commit 8eb7deb464

View File

@ -9,6 +9,7 @@ from os import path
import re
numbers = re.compile("[0-9]+")
name_from_url = re.compile(r"https:\/\/helixnebula.space/(.*)/")
out_dir = "/var/www/html/"
gemini_out_dir = "/var/gemini/"
base_url = "https://helixnebula.space/"
@ -123,6 +124,16 @@ def render_places():
"photos_json": photos_json
}))
def sub_http_local_urls(match):
name = match.group(1)
post_names = [
path.basename(post).split('/')[-1][:-3] for post in glob(md_dir + "*")
]
if name in post_names:
return name + ".gmi"
else:
return match.group(0)
def render_gemini_index():
template = template_environment.get_template("gemini_main")
post_names = [
@ -143,7 +154,10 @@ def render_gemini_places():
content = f.read()
process = Popen(["gemgen"], stdout=PIPE, stdin=PIPE, stderr=PIPE, text=True)
with open(gemini_out_dir + post_name + ".gmi", "w") as f:
f.write(process.communicate(input=content)[0])
header = f"=> https://helixnebula.space/{post_name}/ Link to photography.\n\n"
gemtext = process.communicate(input=content)[0]
gemtext_with_local_urls = name_from_url.sub(sub_http_local_urls, gemtext)
f.write(header + gemtext_with_local_urls)
def copy_files():
call("cp js/* html/js/", shell=True)