This is a gentle fork from https://framagit.org/marienfressinaud/photos.marienfressinaud.fr with a responsive and optimized mindset. https://media.larlet.fr/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

boop.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python3
  2. import os
  3. from jinja2 import Environment, PackageLoader, select_autoescape
  4. from configuration import THEME
  5. PICTURES_DIR_NAME = "photos"
  6. OUTPUT_DIR_NAME = "output"
  7. def list_galleries_in(path):
  8. return [f for f in os.scandir(path) if f.is_dir()]
  9. def generate_output_dir():
  10. output_path = os.path.join(os.curdir, OUTPUT_DIR_NAME)
  11. if not os.path.isdir(output_path):
  12. os.mkdir(output_path)
  13. return output_path
  14. def generate_index(galleries, output_path):
  15. index_path = os.path.join(output_path, "index.html")
  16. theme_path = os.path.join(os.curdir, THEME)
  17. jinja_env = Environment(
  18. loader=PackageLoader("boop", theme_path), autoescape=select_autoescape(["html"])
  19. )
  20. index_template = jinja_env.get_template("index.html.j2")
  21. with open(index_path, "w") as index_file:
  22. index_file.write(index_template.render(galleries=galleries))
  23. def main():
  24. pictures_folder = os.path.join(os.curdir, PICTURES_DIR_NAME)
  25. galleries = list_galleries_in(pictures_folder)
  26. if len(galleries) > 0:
  27. output_path = generate_output_dir()
  28. generate_index(galleries, output_path)
  29. if __name__ == "__main__":
  30. main()