Browse Source

Add a script to generate basic gallery index

master
Marien Fressinaud 5 years ago
parent
commit
02924870a4
4 changed files with 66 additions and 0 deletions
  1. 15
    0
      Herisson/index.html.j2
  2. 48
    0
      boop.py
  3. 1
    0
      configuration.py
  4. 2
    0
      requirements.txt

+ 15
- 0
Herisson/index.html.j2 View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0" />
<title>Boop</title>
</head>
<body>
<ul>
{% for gallery in galleries -%}
<li>{{ gallery.name }}</li>
{% endfor %}
</ul>
</body>
</html>

+ 48
- 0
boop.py View File

@@ -0,0 +1,48 @@
#!/usr/bin/env python3

import os

from jinja2 import Environment, PackageLoader, select_autoescape

from configuration import THEME


PICTURES_DIR_NAME = "photos"
OUTPUT_DIR_NAME = "output"


def list_galleries_in(path):
return [f for f in os.scandir(path) if f.is_dir()]


def generate_output_dir():
output_path = os.path.join(os.curdir, OUTPUT_DIR_NAME)
if not os.path.isdir(output_path):
os.mkdir(output_path)
return output_path


def generate_index(galleries, output_path):
index_path = os.path.join(output_path, "index.html")

theme_path = os.path.join(os.curdir, THEME)
jinja_env = Environment(
loader=PackageLoader("boop", theme_path), autoescape=select_autoescape(["html"])
)
index_template = jinja_env.get_template("index.html.j2")

with open(index_path, "w") as index_file:
index_file.write(index_template.render(galleries=galleries))


def main():
pictures_folder = os.path.join(os.curdir, PICTURES_DIR_NAME)
galleries = list_galleries_in(pictures_folder)

if len(galleries) > 0:
output_path = generate_output_dir()
generate_index(galleries, output_path)


if __name__ == "__main__":
main()

+ 1
- 0
configuration.py View File

@@ -0,0 +1 @@
THEME = "Herisson"

+ 2
- 0
requirements.txt View File

@@ -0,0 +1,2 @@
black
Jinja2

Loading…
Cancel
Save