add: gen html

This commit is contained in:
starnakin 2025-04-14 17:04:47 +02:00
parent 637e2382b2
commit c68f393703
2 changed files with 61 additions and 14 deletions

View File

@ -4,6 +4,10 @@ from progress.bar import Bar
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
import subprocess import subprocess
import time import time
import markdown
env = Environment(loader=FileSystemLoader('src/templates'))
page_template = env.get_template('page.jinja')
def argument_parsing(): def argument_parsing():
if (len(sys.argv) < 2): if (len(sys.argv) < 2):
@ -20,14 +24,16 @@ def get_exif(folder: str, raw: str):
os.remove(absolut_path) os.remove(absolut_path)
return None return None
def get_images(files): def get_images(folder: str, files: list[str]):
length: int = len(folder) + 1
images_datas: list[str] = [] images_datas: list[str] = []
images: list[str] = [file for file in files if os.path.isfile(file) and file.endswith(".png")] images: list[str] = [file for file in files if os.path.isfile(file) and file.endswith(".png")]
for image in images: for image in images:
export_data_file: str = image + ".out.pp3" export_data_file: str = image + ".out.pp3"
if (os.path.exists(export_data_file) and os.path.isfile(export_data_file)): 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[length:], export_data_file[length:]))
images_datas.append((image,)) else:
images_datas.append((image[length:],))
return images_datas return images_datas
def get_updated_folders(path: str): def get_updated_folders(path: str):
@ -56,15 +62,40 @@ def get_readme(folder):
return absolut_path return absolut_path
return None 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]): def gen_pages(folders: list[str]):
with Bar("generating...", max=len(folders)) as bar: with Bar("generating...", max=len(folders)) as bar:
for folder in folders: for folder in folders:
files: list[str] = [os.path.join(folder, file) for file in os.listdir(folder)] files: list[str] = [os.path.join(folder, file) for file in os.listdir(folder)]
images: list[str] = get_images(files) images: list[str] = get_images(folder, files)
raws: list[str] = [file for file in files if file.endswith(".NEF")] raw: str = get_raw(folder, files)
raw: str = raws[0] if len(raws) > 0 else None
if len(images) == 0:
bar.next()
continue
exif: str = get_exif(folder, raw) exif: str = get_exif(folder, raw)
readme: str = get_readme(folder) 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() bar.next()
def main(): def main():

View File

@ -1,20 +1,36 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<link rel="stylesheet" href="../general/page.css"> <link rel="stylesheet" href="../page.css">
</head> </head>
<body> <body>
{% if readme %} {% if readme %}
<div class="readme">
<div class="readme-content">
{{readme}} {{readme}}
</div>
</div>
{% endif %} {% endif %}
{% for image in images %} {% for image in images %}
<img src="{{ image }}"> <div class="image-container">
{% endfor %} <div class="image-container-element">
{% if exif %} <img src='{{ image[0] }}'>
<a href="{{ exif }}">Exif</a> {% if image | length > 1 %}
<a class="export" href="{{ image[1] }}">export file</a>
{% endif %} {% endif %}
</div>
</div>
{% endfor %}
{% if raw or exif %}
<div class="download">
<h1>Download</h1>
{% if raw %} {% if raw %}
<a href="{{ raw }}">RAW</a> <a href="{{ raw }}">RAW</a>
{% endif %} {% endif %}
{% if exif %}
<a href="{{ exif }}">Exif</a>
{% endif %}
</div>
{% endif %}
</body> </body>
</html> </html>