From 431f93d2863babe3362a765507945cbfe987cd05 Mon Sep 17 00:00:00 2001 From: Botond Hende Date: Sun, 5 Apr 2026 12:19:18 +0200 Subject: make generating all subdomains for local testing functional --- __main__.py | 9 +++++++-- blog/templates/blog_feed.xml.j2 | 2 +- blog/templates/sidebar.html.j2 | 10 +++++----- comic/templates/comic_feed.xml.j2 | 2 +- comic/templates/issue.html.j2 | 2 +- config.py | 17 +++++++++++++++++ modules/blog_generate.py | 2 +- modules/comic_generate.py | 3 +-- 8 files changed, 34 insertions(+), 13 deletions(-) diff --git a/__main__.py b/__main__.py index 63f7250..0379275 100644 --- a/__main__.py +++ b/__main__.py @@ -15,13 +15,18 @@ def init_jinja_env() -> jinja2.Environment: def main(output_root_path: str, local: bool): if local: - Config.BLOG_ROOT_URL = "http://localhost" - Config.COMIC_ROOT_URL = "http://localhost" + Config.change_config_to_local() jinja_env = init_jinja_env() jinja_env.globals.update(site={ "assets_path": Config.ASSETS_IMPORT_PATH, "assets_path_static": Config.ASSETS_IMPORT_PATH_STATIC, + "rss_filename": Config.RSS_FILE_NAME, + "main_url": Config.MAIN_ROOT_URL, + "blog_url": Config.BLOG_ROOT_URL, + "comic_url": Config.COMIC_ROOT_URL, + "codenames_url": Config.CODENAMES_ROOT_URL, + "git_url": Config.GIT_ROOT_URL, }) blog_generate.generate(jinja_env, os.path.join(output_root_path, "blog"), local) diff --git a/blog/templates/blog_feed.xml.j2 b/blog/templates/blog_feed.xml.j2 index 1133d85..1061598 100644 --- a/blog/templates/blog_feed.xml.j2 +++ b/blog/templates/blog_feed.xml.j2 @@ -2,7 +2,7 @@ @yggdrasil - https://blog.wazul.moe/feed.xml + {{ site.blog_url }}/{{ site.rss_filename }} The chronicle of my works and learnings en {{ build_date }} diff --git a/blog/templates/sidebar.html.j2 b/blog/templates/sidebar.html.j2 index d20aa44..01625c2 100644 --- a/blog/templates/sidebar.html.j2 +++ b/blog/templates/sidebar.html.j2 @@ -9,11 +9,11 @@ Sometimes I touch upon some more artistic stuff, but mostly just to amuse myself

My other thingies

- + Website - + Comics @@ -21,7 +21,7 @@ Sometimes I touch upon some more artistic stuff, but mostly just to amuse myself Mastodon - + Git repositories @@ -43,7 +43,7 @@ Sometimes I touch upon some more artistic stuff, but mostly just to amuse myself .pinky-swear.sh

Never miss a post

- + RSS feed @@ -56,4 +56,4 @@ Sometimes I touch upon some more artistic stuff, but mostly just to amuse myself

Thank you

for everyone who made this blog possible

How It's Made

-

This blog is open source, check it out!

+

This blog is open source, check it out!

diff --git a/comic/templates/comic_feed.xml.j2 b/comic/templates/comic_feed.xml.j2 index eeb177d..3a8bcc8 100644 --- a/comic/templates/comic_feed.xml.j2 +++ b/comic/templates/comic_feed.xml.j2 @@ -2,7 +2,7 @@ {{ comic.comic_name }} - https://comic.wazul.moe/feed.xml + {{ site.comic_url }}/{{ site.rss_filename }} Silly comic ideas by Wazul en {{ build_date }} diff --git a/comic/templates/issue.html.j2 b/comic/templates/issue.html.j2 index 9a7765c..181604f 100644 --- a/comic/templates/issue.html.j2 +++ b/comic/templates/issue.html.j2 @@ -44,7 +44,7 @@

Image url: {{ url }}/comic.png

{{ issue.get_publish_date() }}


- + RSS feed diff --git a/config.py b/config.py index d8bdd7d..a86475d 100644 --- a/config.py +++ b/config.py @@ -6,6 +6,8 @@ class Config: __DIR = os.path.dirname(__file__) ASSETS_IMPORT_PATH = "/assets" ASSETS_IMPORT_PATH_STATIC = "https://static.wazul.moe" + MAIN_ROOT_URL = "https://wazul.moe" + GIT_ROOT_URL = "https://git.wazul.moe" RSS_FILE_NAME = "feed.xml" TIMEZONE = datetime.timezone(datetime.timedelta(hours=2)) @@ -40,3 +42,18 @@ class Config: CODENAMES_ROOT_URL = "https://codenames.wazul.moe" CODENAMES_ASSETS_SOURCE_DIR = os.path.join(__DIR, "codenames/assets") + + # HELPER FUNCTIONS + @staticmethod + def change_url_to_local(url: str) -> str: + return url.replace("https://", "http://").replace("wazul.moe", "localhost") + + @staticmethod + def change_config_to_local(): + Config.ASSETS_IMPORT_PATH_STATIC = Config.change_url_to_local(Config.ASSETS_IMPORT_PATH_STATIC) + Config.MAIN_ROOT_URL = Config.change_url_to_local(Config.MAIN_ROOT_URL) + Config.GIT_ROOT_URL = Config.change_url_to_local(Config.GIT_ROOT_URL) + Config.BLOG_ROOT_URL = Config.change_url_to_local(Config.BLOG_ROOT_URL) + Config.COMIC_ROOT_URL = Config.change_url_to_local(Config.COMIC_ROOT_URL) + Config.CODENAMES_ROOT_URL = Config.change_url_to_local(Config.CODENAMES_ROOT_URL) + diff --git a/modules/blog_generate.py b/modules/blog_generate.py index 904050d..3bf21be 100644 --- a/modules/blog_generate.py +++ b/modules/blog_generate.py @@ -103,7 +103,7 @@ def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool): "build_date": email.utils.format_datetime(datetime.datetime.now(Config.TIMEZONE)), "posts": posts[:5] } - with open(os.path.join(output_root_path, "feed.xml"), "w") as f: + with open(os.path.join(output_root_path, Config.RSS_FILE_NAME), "w") as f: f.write(rss_template.render(ctx)) shutil.copytree(Config.BLOG_ASSETS_SOURCE_DIR, output_root_path + Config.ASSETS_IMPORT_PATH) \ No newline at end of file diff --git a/modules/comic_generate.py b/modules/comic_generate.py index f30366e..cb12161 100644 --- a/modules/comic_generate.py +++ b/modules/comic_generate.py @@ -68,7 +68,6 @@ def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool): jinja_env.globals.update(comic={ "comic_name": Config.COMIC_NAME, - "comic_url": Config.COMIC_ROOT_URL, }) issues = get_issues(Config.ISSUE_SOURCE_DIR, local) @@ -104,6 +103,6 @@ def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool): "build_date": email.utils.format_datetime(datetime.datetime.now(Config.TIMEZONE)), "issues": issues[:5] } - with open(os.path.join(output_root_path, "feed.xml"), "w") as f: + with open(os.path.join(output_root_path, Config.RSS_FILE_NAME), "w") as f: f.write(rss_template.render(ctx)) -- cgit v1.2.3-70-g09d2