Bläddra i källkod

Add basic support for private galleries

master
Marien Fressinaud 6 år sedan
förälder
incheckning
7020ccf7dc
2 ändrade filer med 29 tillägg och 17 borttagningar
  1. 8
    6
      Herisson/index.html.j2
  2. 21
    11
      boop.py

+ 8
- 6
Herisson/index.html.j2 Visa fil

@@ -23,12 +23,14 @@
<div class="galleries">
{% for gallery in galleries -%}
<div class="gallery-cover">
<a href="{{ gallery.url }}">
<img src="{{ gallery.cover_photo.thumb_url }}" alt="" />
<span class="gallery-cover-name">
{{ gallery.name }}
</span>
</a>
{% if not gallery.private %}
<a href="{{ gallery.url }}">
<img src="{{ gallery.cover_photo.thumb_url }}" alt="" />
<span class="gallery-cover-name">
{{ gallery.name }}
</span>
</a>
{% endif %}
</div>
{% endfor %}
</div>

+ 21
- 11
boop.py Visa fil

@@ -20,17 +20,26 @@ OUTPUT_DIR_NAME = "output"
def list_galleries_in(path):
gallery_dirs = [f for f in os.scandir(path) if f.is_dir()]
for gallery_dir in gallery_dirs:
photos = list(list_photos_in(gallery_dir))
if len(photos) == 0:
continue
photos.sort(key=itemgetter("name"))

metadata = {}
metadata_path = os.path.join(gallery_dir.path, "metadata.yml")
if os.path.exists(metadata_path):
with open(metadata_path, "r") as metadata_file:
metadata = yaml.load(metadata_file)

private = False
url = f"{gallery_dir.name}.html"
output_path = gallery_dir.name
password = metadata.get("password", None)
if password:
private = True
url = f"{gallery_dir.name}-{password}.html"
output_path = f"{output_path}-{password}"

photos = list(list_photos_in(gallery_dir, output_path))
if len(photos) == 0:
continue
photos.sort(key=itemgetter("name"))

# Try to get cover from metadata, if it doesn't exist, take one by
# default.
cover_photo = None
@@ -44,11 +53,12 @@ def list_galleries_in(path):
gallery = {
"name": metadata.get("name", gallery_dir.name),
"path": gallery_dir.path,
"output_path": gallery_dir.name,
"url": f"{gallery_dir.name}.html",
"output_path": output_path,
"url": url,
"num_photos": len(photos),
"photos": photos,
"cover_photo": cover_photo,
"private": private,
}
yield gallery

@@ -61,13 +71,13 @@ def find_photo(photos, photo_name):
return None


def list_photos_in(gallery_dir):
def list_photos_in(gallery_dir, gallery_output_path):
photo_files = [
f for f in os.scandir(gallery_dir) if re.match(".+\.jpg", f.name, re.I)
]
for photo_file in photo_files:
url = os.path.join(gallery_dir.name, photo_file.name)
thumb_url = os.path.join(gallery_dir.name, f"thumb_{photo_file.name}")
url = os.path.join(gallery_output_path, photo_file.name)
thumb_url = os.path.join(gallery_output_path, f"thumb_{photo_file.name}")
photo = {
"name": photo_file.name,
"path": photo_file.path,
@@ -228,7 +238,7 @@ def main():
generate_index(output_path, galleries)
print("✔️")
for gallery in galleries:
print(f"Generating {gallery['name']} gallery... ", end="")
print(f"Generating {gallery['name']} gallery ({gallery['url']})... ", end="")
generate_gallery(output_path, gallery)
print("✔️")
print("Galleries generated 🎉")

Laddar…
Avbryt
Spara