This commit is contained in:
2024-12-01 14:31:35 +01:00
parent cc64d3012a
commit 3831d57fe6
4 changed files with 99 additions and 5 deletions

View File

@ -15,7 +15,7 @@ with open('config.json', 'r') as file:
# Initialiser l'environnement avec un dossier de templates
env = Environment(loader=FileSystemLoader('src/templates'))
template = env.get_template('index.html')
template = env.get_template('page.html')
def get_files_recursive(directory):
file_paths = []
@ -63,7 +63,10 @@ def get_exif(raws: list[str]):
def generate_page(output_path: str):
for folder in os.listdir(output_path):
folders = os.listdir(output_path)
if "general" in folders:
folders.remove("general")
for folder in folders:
path = os.path.join(output_path, folder)
if (os.path.isdir(path)):
files: list[str] = [os.path.join(path, file) for file in os.listdir(path) if os.path.isfile(os.path.join(path, file))]
@ -72,6 +75,7 @@ def generate_page(output_path: str):
larges = [file for ext in config["file_type_extensions"]["large"] for file in files if file.endswith(ext)]
smalls = [file for ext in config["file_type_extensions"]["small"] for file in files if file.endswith(ext)]
print(folder)
generate_missing_images(raws, larges, smalls)
exif = get_exif(raws)
@ -79,6 +83,7 @@ def generate_page(output_path: str):
large = os.path.basename(larges[0]) if len(larges) > 0 else None
small = os.path.basename(smalls[0]) if len(smalls) > 0 else None
print(f"Generate {folder} html")
html_rendered = template.render(exif=exif, raw=raw, large=large, small=small)
with open(os.path.join(path, f"{folder}.html"), "w") as f:
@ -99,5 +104,10 @@ def main():
generate_page(output_path)
general_path: str = os.path.join(output_path, "general")
if not os.path.exists(general_path):
#os.makedirs(general_path)
shutil.copytree("src/templates/", general_path)
if (__name__ == "__main__"):
main()