diff options
Diffstat (limited to 'modules/comic_generate.py')
| -rw-r--r-- | modules/comic_generate.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/modules/comic_generate.py b/modules/comic_generate.py index 9c88d67..76705fa 100644 --- a/modules/comic_generate.py +++ b/modules/comic_generate.py @@ -33,6 +33,12 @@ class Issue: def get_publish_time(self) -> str: return self.meta_data[PUBLISH_DATE_KEY] + def get_publish_time_rfc2822(self) -> str: + return email.utils.format_datetime(datetime.datetime.fromisoformat(self.get_publish_time() + " 12:00+02:00")) + + def get_link(self) -> str: + return f"{Config.COMIC_ROOT_URL}/issues/{self.index}" + def get_issues(path: str, local: bool) -> list[Issue]: return_list = [] @@ -55,6 +61,7 @@ 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) @@ -67,7 +74,7 @@ def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool): ctx = { "issue": issue, - "url": f"{Config.COMIC_ROOT_URL}/issues/{issue.index}" + "url": issue.get_link() } last_render = issue_template.render(ctx) @@ -80,3 +87,11 @@ def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool): f.write(last_render) shutil.copytree(Config.COMIC_ASSETS_SOURCE_DIR, output_root_path + Config.ASSETS_IMPORT_PATH) + rss_template = jinja_env.get_template("comic_feed.xml.j2") + ctx = { + "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: + f.write(rss_template.render(ctx)) + |
