diff --git a/src/main.py b/src/main.py index 8009530..8163231 100644 --- a/src/main.py +++ b/src/main.py @@ -4,6 +4,10 @@ from progress.bar import Bar from jinja2 import Environment, FileSystemLoader import subprocess import time +import markdown + +env = Environment(loader=FileSystemLoader('src/templates')) +page_template = env.get_template('page.jinja') def argument_parsing(): if (len(sys.argv) < 2): @@ -20,14 +24,16 @@ def get_exif(folder: str, raw: str): os.remove(absolut_path) return None -def get_images(files): +def get_images(folder: str, files: list[str]): + length: int = len(folder) + 1 images_datas: list[str] = [] images: list[str] = [file for file in files if os.path.isfile(file) and file.endswith(".png")] for image in images: export_data_file: str = image + ".out.pp3" if (os.path.exists(export_data_file) and os.path.isfile(export_data_file)): - images_datas.append((image, export_data_file)) - images_datas.append((image,)) + images_datas.append((image[length:], export_data_file[length:])) + else: + images_datas.append((image[length:],)) return images_datas def get_updated_folders(path: str): @@ -56,15 +62,40 @@ def get_readme(folder): return absolut_path return None +def get_raw(folder, files: list[str]): + raws: list[str] = [file for file in files if file.endswith(".NEF")] + raw: str = raws[0] if len(raws) > 0 else None + return raw[len(folder) + 1:] + +def get_html_readme(readme_path: str): + if readme_path is None: + return None + with open(readme_path, 'r') as f: + text = f.read() + html = markdown.markdown(text) + return html + def gen_pages(folders: list[str]): with Bar("generating...", max=len(folders)) as bar: for folder in folders: + files: list[str] = [os.path.join(folder, file) for file in os.listdir(folder)] - images: list[str] = get_images(files) - raws: list[str] = [file for file in files if file.endswith(".NEF")] - raw: str = raws[0] if len(raws) > 0 else None + images: list[str] = get_images(folder, files) + raw: str = get_raw(folder, files) + + if len(images) == 0: + bar.next() + continue + exif: str = get_exif(folder, raw) readme: str = get_readme(folder) + readme_html: str = get_html_readme(readme) + + html_rendered = page_template.render(exif=exif, raw=raw, images=images, readme=readme_html) + + with open(os.path.join(folder, "page.html"), "w") as f: + f.write(html_rendered) + bar.next() def main(): diff --git a/src/templates/page.jinja b/src/templates/page.jinja index 3c8434b..173af7f 100644 --- a/src/templates/page.jinja +++ b/src/templates/page.jinja @@ -1,20 +1,36 @@
- + {% if readme %} - {{readme}} +