This is a gentle fork from https://framagit.org/marienfressinaud/photos.marienfressinaud.fr with a responsive and optimized mindset. https://media.larlet.fr/
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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