From ecc41e86cd3131d03f070dba36ae77f2961c6185 Mon Sep 17 00:00:00 2001 From: deadvey Date: Mon, 31 Mar 2025 16:08:56 +0100 Subject: [PATCH] file extension option in config to allow for usage on a html server --- create_pages.py | 22 +++++++++++----------- parse_post.py | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/create_pages.py b/create_pages.py index 9fb18f8..67f737f 100644 --- a/create_pages.py +++ b/create_pages.py @@ -1,16 +1,16 @@ # File tree: # -# / -- index.gmi +# / -- index.{config.file_extension} # | -# |- post/ -- 1.gmi +# |- post/ -- 1.{config.file_extension} # | | -# | |- 2.gmi +# | |- 2.{config.file_extension} # | | -# | |- 3.gmi +# | |- 3.{config.file_extension} # | -# |- user/ -- deadvey.gmi +# |- user/ -- deadvey.{config.file_extension} # | -# |- max.gmi +# |- max.{config.file_extension} # import config @@ -29,7 +29,7 @@ from datetime import datetime def create_user_page(userID, username): try: - with open(f"{config.webroot}/user/{username}.gmi", "w") as userfile: + with open(f"{config.webroot}/user/{username}.{config.file_extension}", "w") as userfile: output.log("Writing posts to userfile") userfile.write(f"# {username}:\n") for post_index in range(len(posts.posts)-1,-1,-1): @@ -37,23 +37,23 @@ def create_user_page(userID, username): post_content = parse_post.parse_post_format(post_content, post_index, username) userfile.write(post_content) except: - print(f"Unable to open {username}.gmi") + print(f"Unable to open {username}.{config.file_extension}") initialise.initialise() def create_post_page(post_index): try: - with open(f"{config.webroot}/post/{post_index}.gmi", "w") as postfile: + with open(f"{config.webroot}/post/{post_index}.{config.file_extension}", "w") as postfile: output.log("Writing post to postfile") output.log(posts.posts[post_index]) postfile_content = config.post_page_post_format postfile_content = parse_post.parse_post_format(postfile_content, post_index, users.users[posts.posts[post_index]["userID"]]) postfile.write(postfile_content) except: - print(f"Unable to open {post_index}.gmi") + print(f"Unable to open {post_index}.{config.file_extension}") initialise.initialise() def create_timeline(): - with open(f"{config.webroot}/index.gmi", "w") as timeline_file: + with open(f"{config.webroot}/index.{config.file_extension}", "w") as timeline_file: output.log("Writing posts to timeline") for current_post_index in range(len(posts.posts)-1,-1,-1): username = users.users[posts.posts[current_post_index]["userID"]] diff --git a/parse_post.py b/parse_post.py index 01022e5..84d9f18 100644 --- a/parse_post.py +++ b/parse_post.py @@ -9,8 +9,8 @@ def parse_post_format(post, post_index, username): post = post.replace("%D", datetime.strptime(str(post_data["pubdate"]),"%d%m%YZ%H%M%ST").strftime(config.date_format)) post = post.replace("%E", datetime.strptime(str(post_data["editdate"]),"%d%m%YZ%H%M%ST").strftime(config.date_format)) post = post.replace("%C", post_data["content"]) - post = post.replace("%L", f"{config.site_url}/post/{post_index}.gmi") - post = post.replace("%U", f"{config.site_url}/user/{username}.gmi") + post = post.replace("%L", f"{config.site_url}/post/{post_index}.{config.file_extension}") + post = post.replace("%U", f"{config.site_url}/user/{username}.{config.file_extension}") post = post.replace("%N", username) return post