Hero carrousel in gallery.py instead of site.yaml + removed deleted img for gallery.py
9
build.py
@ -31,7 +31,7 @@ def build():
|
|||||||
build_date = datetime.now().strftime("%Y%m%d%H%M%S")
|
build_date = datetime.now().strftime("%Y%m%d%H%M%S")
|
||||||
build_date_version = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
build_date_version = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
site_vars = load_yaml(SITE_FILE)
|
site_vars = load_yaml(SITE_FILE)
|
||||||
gallery_sections = load_yaml(GALLERY_FILE)
|
gallery_vars = load_yaml(GALLERY_FILE)
|
||||||
build_section = site_vars.get("build", {})
|
build_section = site_vars.get("build", {})
|
||||||
theme_name = site_vars.get("build", {}).get("theme", "default")
|
theme_name = site_vars.get("build", {}).get("theme", "default")
|
||||||
theme_vars, theme_dir = load_theme_config(theme_name, THEMES_DIR)
|
theme_vars, theme_dir = load_theme_config(theme_name, THEMES_DIR)
|
||||||
@ -63,8 +63,8 @@ def build():
|
|||||||
logging.info(f"[~] convert_images = {convert_images}")
|
logging.info(f"[~] convert_images = {convert_images}")
|
||||||
logging.info(f"[~] resize_images = {resize_images}")
|
logging.info(f"[~] resize_images = {resize_images}")
|
||||||
|
|
||||||
hero_images = site_vars.get("hero", {}).get("images", [])
|
hero_images = gallery_vars.get("hero", {}).get("images", [])
|
||||||
gallery_images = [img for section in gallery_sections for img in section["images"]] if isinstance(gallery_sections, list) else gallery_sections.get("images", [])
|
gallery_images = gallery_vars.get("gallery", {}).get("images", [])
|
||||||
|
|
||||||
if convert_images:
|
if convert_images:
|
||||||
process_images(hero_images, resize_images, IMG_DIR, BUILD_DIR)
|
process_images(hero_images, resize_images, IMG_DIR, BUILD_DIR)
|
||||||
@ -73,6 +73,9 @@ def build():
|
|||||||
copy_original_images(hero_images, IMG_DIR, BUILD_DIR)
|
copy_original_images(hero_images, IMG_DIR, BUILD_DIR)
|
||||||
copy_original_images(gallery_images, IMG_DIR, BUILD_DIR)
|
copy_original_images(gallery_images, IMG_DIR, BUILD_DIR)
|
||||||
|
|
||||||
|
if "hero" not in site_vars:
|
||||||
|
site_vars["hero"] = {} # Initialize an empty hero section
|
||||||
|
|
||||||
# Adding menu
|
# Adding menu
|
||||||
menu_html = "\n".join(
|
menu_html = "\n".join(
|
||||||
f'<li class="nav-item appear"><a href="{item["href"]}">{item["label"]}</a></li>'
|
f'<li class="nav-item appear"><a href="{item["href"]}">{item["label"]}</a></li>'
|
||||||
|
@ -1,2 +1,7 @@
|
|||||||
# Use gallery.py to automatically add photos stored in your /config/photos/gallery folder.
|
# Use gallery.py to automatically add photos stored in your /config/photos/gallery folder
|
||||||
images: []
|
# Add tags to your photos as shown below
|
||||||
|
# remove the # before [] if you removed all images to use gallery.py again
|
||||||
|
hero:
|
||||||
|
images: []
|
||||||
|
gallery:
|
||||||
|
images: []
|
Before Width: | Height: | Size: 2.7 MiB |
Before Width: | Height: | Size: 1.5 MiB |
Before Width: | Height: | Size: 2.7 MiB |
Before Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 5.7 MiB |
Before Width: | Height: | Size: 2.7 MiB |
Before Width: | Height: | Size: 364 KiB |
Before Width: | Height: | Size: 5.6 MiB |
Before Width: | Height: | Size: 8.4 MiB |
Before Width: | Height: | Size: 706 KiB |
Before Width: | Height: | Size: 2.7 MiB |
Before Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 1.1 MiB |
@ -10,16 +10,12 @@ info:
|
|||||||
social:
|
social:
|
||||||
instagram_url:
|
instagram_url:
|
||||||
thumbnail:
|
thumbnail:
|
||||||
|
|
||||||
menu:
|
menu:
|
||||||
items:
|
items:
|
||||||
- label: Home
|
- label: Home
|
||||||
href: /
|
href: /
|
||||||
|
|
||||||
hero:
|
|
||||||
# Use gallery.py to automatically add images from config/photos/hero folder
|
|
||||||
images: []
|
|
||||||
|
|
||||||
footer:
|
footer:
|
||||||
copyright: Copyright © 2025
|
copyright: Copyright © 2025
|
||||||
legal_link: '/legals/'
|
legal_link: '/legals/'
|
||||||
|
@ -1,30 +1,36 @@
|
|||||||
# Source your photos here
|
# Use gallery.py to automatically add photos stored in your /config/photos/gallery folder
|
||||||
# Relative path is set from built img folder
|
|
||||||
# You can also use gallery.py to automatically add photos stored in your /config/photos/gallery folder
|
|
||||||
# Add tags to your photos as shown below
|
# Add tags to your photos as shown below
|
||||||
# remove the # before [] if you removed all images to use gallery.py
|
# remove the # before [] if you removed all images to use gallery.py again
|
||||||
images: #[]
|
|
||||||
- src: gallery/almos-bechtold-3402kvtHhOo-unsplash.jpg
|
hero:
|
||||||
tags: ["portrait"]
|
images: #[]
|
||||||
- src: gallery/arthur-savary-nLfAqmZ2hJo-unsplash.jpg
|
- src: hero/francesco-ungaro-Zbc9Ka8msdI-unsplash.jpg
|
||||||
tags: ["portrait", "sunset", "boat"]
|
- src: hero/gilley-aguilar-ywGDhTlf93E-unsplash.jpg
|
||||||
- src: gallery/francesco-ungaro-Zbc9Ka8msdI-unsplash.jpg
|
- src: hero/jacob-reinikainen-nGG6m3RbjSk-unsplash.jpg
|
||||||
tags: ["landscape", "sea", "beach", "sand"]
|
|
||||||
- src: gallery/gilley-aguilar-ywGDhTlf93E-unsplash.jpg
|
gallery:
|
||||||
tags: ["landscape", "sky", "cloud", "mountains"]
|
images: #[]
|
||||||
- src: gallery/jacob-reinikainen-nGG6m3RbjSk-unsplash.jpg
|
- src: gallery/almos-bechtold-3402kvtHhOo-unsplash.jpg
|
||||||
tags: ["lanscape", "sunset", "mountains"]
|
tags: [portrait]
|
||||||
- src: gallery/jonas-degener-LueP5EdWGFY-unsplash.jpg
|
- src: gallery/arthur-savary-nLfAqmZ2hJo-unsplash.jpg
|
||||||
tags: ["landscape", "mountains", "fog"]
|
tags: [portrait, sunset, boat]
|
||||||
- src: gallery/michiel-annaert-M27pZnHV6M0-unsplash.jpg
|
- src: gallery/francesco-ungaro-Zbc9Ka8msdI-unsplash.jpg
|
||||||
tags: ["flowers", "nature"]
|
tags: [landscape, sea, beach, sand]
|
||||||
- src: gallery/nir-himi-AjecvkfSHxA-unsplash.jpg
|
- src: gallery/gilley-aguilar-ywGDhTlf93E-unsplash.jpg
|
||||||
tags: ["landscape", "mountains", "sky"]
|
tags: [landscape, sky, cloud, mountains]
|
||||||
- src: gallery/rachel-mcdermott-0fN7Fxv1eWA-unsplash.jpg
|
- src: gallery/jacob-reinikainen-nGG6m3RbjSk-unsplash.jpg
|
||||||
tags: ["portrait", "black and white"]
|
tags: [lanscape, sunset, mountains]
|
||||||
- src: gallery/tianlei-wu-g5o6T-PWT3g-unsplash.jpg
|
- src: gallery/jonas-degener-LueP5EdWGFY-unsplash.jpg
|
||||||
tags: ["cat", "animals"]
|
tags: [landscape, mountains, fog]
|
||||||
- src: gallery/we-care-wild-zLweeVLU9Fo-unsplash.jpg
|
- src: gallery/michiel-annaert-M27pZnHV6M0-unsplash.jpg
|
||||||
tags: ["bison", "animals"]
|
tags: [flowers, nature]
|
||||||
- src: gallery/y-s-z90w7yStOkk-unsplash.jpg
|
- src: gallery/nir-himi-AjecvkfSHxA-unsplash.jpg
|
||||||
tags: ["frog", "green", "animals"]
|
tags: [landscape, mountains, sky]
|
||||||
|
- src: gallery/rachel-mcdermott-0fN7Fxv1eWA-unsplash.jpg
|
||||||
|
tags: [portrait, black and white]
|
||||||
|
- src: gallery/tianlei-wu-g5o6T-PWT3g-unsplash.jpg
|
||||||
|
tags: [cat, animals]
|
||||||
|
- src: gallery/we-care-wild-zLweeVLU9Fo-unsplash.jpg
|
||||||
|
tags: [bison, animals]
|
||||||
|
- src: gallery/y-s-z90w7yStOkk-unsplash.jpg
|
||||||
|
tags: [frog, green, animals]
|
||||||
|
@ -27,16 +27,6 @@ menu:
|
|||||||
- label: Animals
|
- label: Animals
|
||||||
href: /?tag=animals
|
href: /?tag=animals
|
||||||
|
|
||||||
hero:
|
|
||||||
# Source your hero carrousel images here.
|
|
||||||
# Root folder is img.
|
|
||||||
# You can also use gallery.py to automatically add images from config/photos/hero folder
|
|
||||||
# remove the # before [] if you removed all images to use gallery.py
|
|
||||||
images: #[]
|
|
||||||
- src: hero/francesco-ungaro-Zbc9Ka8msdI-unsplash.jpg
|
|
||||||
- src: hero/gilley-aguilar-ywGDhTlf93E-unsplash.jpg
|
|
||||||
- src: hero/jacob-reinikainen-nGG6m3RbjSk-unsplash.jpg
|
|
||||||
|
|
||||||
footer:
|
footer:
|
||||||
copyright: Copyright © 2025 – Lumeex
|
copyright: Copyright © 2025 – Lumeex
|
||||||
legal_link: '/legals/'
|
legal_link: '/legals/'
|
||||||
|
84
gallery.py
@ -4,7 +4,6 @@ from pathlib import Path
|
|||||||
|
|
||||||
# YAML file paths
|
# YAML file paths
|
||||||
GALLERY_YAML = "config/gallery.yaml"
|
GALLERY_YAML = "config/gallery.yaml"
|
||||||
SITE_YAML = "config/site.yaml"
|
|
||||||
|
|
||||||
# Image directories
|
# Image directories
|
||||||
GALLERY_DIR = Path("config/photos/gallery")
|
GALLERY_DIR = Path("config/photos/gallery")
|
||||||
@ -17,7 +16,7 @@ def load_yaml(path):
|
|||||||
return {}
|
return {}
|
||||||
with open(path, "r", encoding="utf-8") as f:
|
with open(path, "r", encoding="utf-8") as f:
|
||||||
data = yaml.safe_load(f) or {}
|
data = yaml.safe_load(f) or {}
|
||||||
images = data.get("images") or []
|
images = data.get("images", []) or []
|
||||||
print(f"[✓] Loaded {len(images)} image(s) from {path}")
|
print(f"[✓] Loaded {len(images)} image(s) from {path}")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@ -34,47 +33,80 @@ def get_all_image_paths(directory):
|
|||||||
])
|
])
|
||||||
|
|
||||||
def update_gallery():
|
def update_gallery():
|
||||||
print("\n=== Updating gallery.yaml ===")
|
print("\n=== Updating gallery.yaml (gallery section) ===")
|
||||||
gallery = load_yaml(GALLERY_YAML)
|
gallery = load_yaml(GALLERY_YAML)
|
||||||
gallery_images = gallery.get("images") or []
|
|
||||||
known = {img["src"] for img in gallery_images}
|
|
||||||
all_images = get_all_image_paths(GALLERY_DIR)
|
|
||||||
|
|
||||||
|
# Access the 'gallery' section within the gallery data, or initialize it if it doesn't exist
|
||||||
|
gallery_section = gallery.get("gallery", {})
|
||||||
|
|
||||||
|
# Access the 'images' list within the 'gallery' section, or initialize it if it doesn't exist
|
||||||
|
gallery_images = gallery_section.get("images", [])
|
||||||
|
|
||||||
|
all_images = set(get_all_image_paths(GALLERY_DIR))
|
||||||
|
known_images = {img["src"] for img in gallery_images}
|
||||||
|
|
||||||
|
# Add new images
|
||||||
new_images = [
|
new_images = [
|
||||||
{"src": path, "tags": []}
|
{"src": path, "tags": []}
|
||||||
for path in all_images
|
for path in all_images
|
||||||
if path not in known
|
if path not in known_images
|
||||||
]
|
]
|
||||||
|
|
||||||
if new_images:
|
if new_images:
|
||||||
gallery_images.extend(new_images)
|
gallery_images.extend(new_images)
|
||||||
gallery["images"] = gallery_images
|
print(f"[✓] Added {len(new_images)} new image(s) to gallery.yaml (gallery)")
|
||||||
save_yaml(gallery, GALLERY_YAML)
|
|
||||||
print(f"[✓] Added {len(new_images)} new image(s) to gallery.yaml")
|
# Remove deleted images
|
||||||
else:
|
deleted_images = known_images - all_images
|
||||||
print("[✓] No new images to add to gallery.yaml")
|
if deleted_images:
|
||||||
|
gallery_images = [img for img in gallery_images if img["src"] not in deleted_images]
|
||||||
|
print(f"[✓] Removed {len(deleted_images)} deleted image(s) from gallery.yaml (gallery)")
|
||||||
|
|
||||||
|
# Update the 'gallery' section with the modified 'images' list
|
||||||
|
gallery_section["images"] = gallery_images
|
||||||
|
gallery["gallery"] = gallery_section
|
||||||
|
|
||||||
|
save_yaml(gallery, GALLERY_YAML)
|
||||||
|
|
||||||
|
if not new_images and not deleted_images:
|
||||||
|
print("[✓] No changes to gallery.yaml (gallery)")
|
||||||
|
|
||||||
def update_hero():
|
def update_hero():
|
||||||
print("\n=== Updating site.yaml (hero section) ===")
|
print("\n=== Updating gallery.yaml (hero section) ===")
|
||||||
site = load_yaml(SITE_YAML)
|
gallery = load_yaml(GALLERY_YAML)
|
||||||
hero_section = site.get("hero", {})
|
|
||||||
hero_images = hero_section.get("images") or []
|
|
||||||
known = {img["src"] for img in hero_images}
|
|
||||||
all_images = get_all_image_paths(HERO_DIR)
|
|
||||||
|
|
||||||
|
# Access the 'hero' section within the gallery data, or initialize it if it doesn't exist
|
||||||
|
hero_section = gallery.get("hero", {})
|
||||||
|
|
||||||
|
# Access the 'images' list within the 'hero' section, or initialize it if it doesn't exist
|
||||||
|
hero_images = hero_section.get("images", [])
|
||||||
|
|
||||||
|
all_images = set(get_all_image_paths(HERO_DIR))
|
||||||
|
known_images = {img["src"] for img in hero_images}
|
||||||
|
|
||||||
|
# Add new images
|
||||||
new_images = [
|
new_images = [
|
||||||
{"src": path}
|
{"src": path}
|
||||||
for path in all_images
|
for path in all_images
|
||||||
if path not in known
|
if path not in known_images
|
||||||
]
|
]
|
||||||
|
|
||||||
if new_images:
|
if new_images:
|
||||||
hero_images.extend(new_images)
|
hero_images.extend(new_images)
|
||||||
site["hero"]["images"] = hero_images
|
print(f"[✓] Added {len(new_images)} new image(s) to gallery.yaml (hero)")
|
||||||
save_yaml(site, SITE_YAML)
|
|
||||||
print(f"[✓] Added {len(new_images)} new image(s) to site.yaml (hero)")
|
# Remove deleted images
|
||||||
else:
|
deleted_images = known_images - all_images
|
||||||
print("[✓] No new images to add to site.yaml")
|
if deleted_images:
|
||||||
|
hero_images = [img for img in hero_images if img["src"] not in deleted_images]
|
||||||
|
print(f"[✓] Removed {len(deleted_images)} deleted image(s) from gallery.yaml (hero)")
|
||||||
|
|
||||||
|
# Update the 'hero' section with the modified 'images' list
|
||||||
|
hero_section["images"] = hero_images
|
||||||
|
gallery["hero"] = hero_section
|
||||||
|
|
||||||
|
save_yaml(gallery, GALLERY_YAML)
|
||||||
|
|
||||||
|
if not new_images and not deleted_images:
|
||||||
|
print("[✓] No changes to gallery.yaml (hero)")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
update_gallery()
|
update_gallery()
|
||||||
|