add: gen html
This commit is contained in:
parent
637e2382b2
commit
c68f393703
43
src/main.py
43
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():
|
||||
|
@ -1,20 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="../general/page.css">
|
||||
<link rel="stylesheet" href="../page.css">
|
||||
</head>
|
||||
<body>
|
||||
{% if readme %}
|
||||
{{readme}}
|
||||
<div class="readme">
|
||||
<div class="readme-content">
|
||||
{{readme}}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for image in images %}
|
||||
<img src="{{ image }}">
|
||||
<div class="image-container">
|
||||
<div class="image-container-element">
|
||||
<img src='{{ image[0] }}'>
|
||||
{% if image | length > 1 %}
|
||||
<a class="export" href="{{ image[1] }}">export file</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% if exif %}
|
||||
<a href="{{ exif }}">Exif</a>
|
||||
{% endif %}
|
||||
{% if raw %}
|
||||
<a href="{{ raw }}">RAW</a>
|
||||
{% if raw or exif %}
|
||||
<div class="download">
|
||||
<h1>Download</h1>
|
||||
{% if raw %}
|
||||
<a href="{{ raw }}">RAW</a>
|
||||
{% endif %}
|
||||
{% if exif %}
|
||||
<a href="{{ exif }}">Exif</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user