diff options
| -rw-r--r-- | __main__.py | 9 | ||||
| -rw-r--r-- | blog/templates/blog_feed.xml.j2 | 2 | ||||
| -rw-r--r-- | blog/templates/sidebar.html.j2 | 10 | ||||
| -rw-r--r-- | comic/templates/comic_feed.xml.j2 | 2 | ||||
| -rw-r--r-- | comic/templates/issue.html.j2 | 2 | ||||
| -rw-r--r-- | config.py | 17 | ||||
| -rw-r--r-- | modules/blog_generate.py | 2 | ||||
| -rw-r--r-- | 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 @@ <rss version="2.0"> <channel> <title>@yggdrasil</title> - <link>https://blog.wazul.moe/feed.xml</link> + <link>{{ site.blog_url }}/{{ site.rss_filename }}</link> <description>The chronicle of my works and learnings</description> <language>en</language> <lastBuildDate>{{ build_date }}</lastBuildDate> 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 <img src="/assets/image/arch.svg" class="svg-icon" /> </div> <h3 class="magenta">My other thingies</h3> -<a href="https://wazul.moe" class="icon-text" target="_blank"> +<a href="{{ site.main_url }}" class="icon-text" target="_blank"> <img src="/assets/image/website.svg" class="svg-icon filter-yellow" /> <span>Website</span> </a> -<a href="https://comic.wazul.moe" class="icon-text" target="_blank"> +<a href="{{ site.comic_url }}" class="icon-text" target="_blank"> <img src="/assets/image/pencil.svg" class="svg-icon filter-yellow" /> <span>Comics</span> </a> @@ -21,7 +21,7 @@ Sometimes I touch upon some more artistic stuff, but mostly just to amuse myself <img src="/assets/image/mastodon.svg" class="svg-icon" /> <span>Mastodon</span> </a> -<a href="https://git.wazul.moe" class="icon-text" target="_blank"> +<a href="{{ site.git_url }}" class="icon-text" target="_blank"> <img src="/assets/image/git.svg" class="svg-icon" /> <span>Git repositories</span> </a> @@ -43,7 +43,7 @@ Sometimes I touch upon some more artistic stuff, but mostly just to amuse myself <span>.pinky-swear.sh</span> </a> <h3 class="magenta">Never miss a post</h3> -<a href="/feed.xml" class="icon-text"> +<a href="/{{ site.rss_filename }}" class="icon-text"> <img src="/assets/image/rss.svg" class="svg-icon" /> <span>RSS feed</span> </a> @@ -56,4 +56,4 @@ Sometimes I touch upon some more artistic stuff, but mostly just to amuse myself <h3 class="magenta">Thank you</h3> <p>for <a href="/acknowledgement.html">everyone</a> who made this blog possible</p> <h3 class="magenta">How It's Made</h3> -<p class="last-element">This blog is open source, <a href="https://git.wazul.moe/website" target="_blank">check it out!</a></p> +<p class="last-element">This blog is open source, <a href="{{ site.git_url }}/website" target="_blank">check it out!</a></p> 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 @@ <rss version="2.0"> <channel> <title>{{ comic.comic_name }}</title> - <link>https://comic.wazul.moe/feed.xml</link> + <link>{{ site.comic_url }}/{{ site.rss_filename }}</link> <description>Silly comic ideas by Wazul</description> <language>en</language> <lastBuildDate>{{ build_date }}</lastBuildDate> 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 @@ <p>Image url: <a href="{{ url }}/comic.png">{{ url }}/comic.png</a></p> <p>{{ issue.get_publish_date() }}</p> <hr> - <a href="/feed.xml" class="icon-text" target="_blank"> + <a href="/{{ site.rss_filename }}" class="icon-text" target="_blank"> <img src="/assets/image/rss.svg" class="svg-icon" /> <span>RSS feed</span> </a> @@ -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)) |
