diff options
Diffstat (limited to 'modules/comic_generate.py')
| -rw-r--r-- | modules/comic_generate.py | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/modules/comic_generate.py b/modules/comic_generate.py index de8fad8..7c55521 100644 --- a/modules/comic_generate.py +++ b/modules/comic_generate.py @@ -10,17 +10,29 @@ from ..config import Config META_FILE_NAME = "meta.json" IMAGE_FILE_NAME = "comic.png" + +TITLE_KEY = "title" +DESCRIPTION_KEY = "description" PUBLISH_DATE_KEY = "publish_date" class Issue: def __init__(self, path: str): self.path = path - self.name = os.path.basename(path) + self.index = os.path.basename(path) with open(os.path.join(path, META_FILE_NAME)) as f: self.meta_data = json.load(f) + def title(self) -> str: + return self.meta_data[TITLE_KEY] + + def description(self) -> str: + return self.meta_data[DESCRIPTION_KEY] + + def get_publish_time(self) -> str: + return self.meta_data[PUBLISH_DATE_KEY] + def get_issues(path: str, local: bool) -> list[Issue]: return_list = [] @@ -41,6 +53,26 @@ def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool): os.mkdir(output_root_path) - issues = get_issues(Config.POST_SOURCE_DIR, local) + jinja_env.globals.update(comic={ + "comic_name": Config.COMIC_NAME, + }) + + issues = get_issues(Config.ISSUE_SOURCE_DIR, local) + issue_template = jinja_env.get_template("issue.html.j2") + + for issue in issues: + output_dir = os.path.join(output_root_path, "issues", issue.index) + os.makedirs(output_dir, exist_ok=True) + + ctx = { + "issue": issue, + "url": f"{Config.COMIC_ROOT_URL}/issues/{issue.index}" + } + + with open(os.path.join(output_dir, "index.html"), "w") as f: + f.write(issue_template.render(ctx)) + + shutil.copyfile(os.path.join(issue.path, IMAGE_FILE_NAME), os.path.join(output_dir, IMAGE_FILE_NAME)) + shutil.copytree(Config.COMIC_ASSETS_SOURCE_DIR, output_root_path + Config.ASSETS_IMPORT_PATH) |
