From 28f5aacab3bd270ec4b26e6903f2063bd7b81704 Mon Sep 17 00:00:00 2001 From: nebula Date: Thu, 3 Apr 2025 06:14:17 +0000 Subject: [PATCH] refactor name --- generate.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/generate.py b/generate.py index ef746ef..a563529 100644 --- a/generate.py +++ b/generate.py @@ -20,6 +20,11 @@ template_environment = Environment( with open("metadata.json", "r") as f: metadata = load(f) +story_names = [ + path.basename(post).split('/')[-1][:-3] for post in glob(md_dir + "*") +] +story_names.sort() + for placename in metadata.keys(): read_path = f"{out_dir}{placename}/" photos = [ @@ -126,24 +131,17 @@ def render_places(): 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: + if name in story_names: return name + ".gmi" else: return match.group(0) def render_gemini_index(): template = template_environment.get_template("gemini_main") - post_names = [ - path.basename(post).split('/')[-1][:-3] for post in glob(md_dir + "*") - ] - post_names.sort() with open(gemini_out_dir + "index.gmi", "w") as f: f.write(template.render({ - "post_info": {post_name: metadata[post_name]["title"] for post_name in post_names}, - "post_states": {post_name: metadata[post_name]["state"] for post_name in post_names} + "post_info": {post_name: metadata[post_name]["title"] for post_name in story_names}, + "post_states": {post_name: metadata[post_name]["state"] for post_name in story_names} })) def render_gemini_places():