From b5b2c676b32a6af9f09084fd74871570bec51cda Mon Sep 17 00:00:00 2001 From: Kylian Schmidt Date: Mon, 7 Jul 2025 15:26:01 +0200 Subject: [PATCH] Update --- .gitignore | 1 + generate_gallery.py | 84 ++++++++- template.html | 406 +++++++++++++++++++++++++++++++++++--------- 3 files changed, 406 insertions(+), 85 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/generate_gallery.py b/generate_gallery.py index 22d0f65..6b8dee4 100644 --- a/generate_gallery.py +++ b/generate_gallery.py @@ -143,18 +143,88 @@ def build_gallery(source_dir: Path, web_dir: Path, else: title = f"Gallery: {relative_path}" + # Calculate statistics for current directory + current_stats = calculate_directory_stats(web_dir) + stats = { + "file_count": len(items), + "folder_count": len(subdir_names), + "total_size": format_file_size(current_stats["total_size"]), + "total_size_bytes": current_stats["total_size"] + } + with output_html.open("w") as f: f.write(template.render( title=title, items=items, subdirs=subdir_names, relpath=str(relative_path), - ui=CONFIG.ui + ui=CONFIG.ui, + stats=stats )) print(f"Generated {output_html}") +def calculate_directory_stats(directory: Path) -> dict: + """ + Calculate statistics for a directory. + + Args: + directory: Path to the directory to analyze + + Returns: + Dictionary containing file count, folder count, and total size + """ + stats = { + "file_count": 0, + "folder_count": 0, + "total_size": 0, + "pdf_size": 0, + "png_size": 0 + } + + if not directory.exists(): + return stats + + for item in directory.rglob("*"): + if item.is_file(): + stats["file_count"] += 1 + size = item.stat().st_size + stats["total_size"] += size + + if item.suffix.lower() == '.pdf': + stats["pdf_size"] += size + elif item.suffix.lower() == '.png': + stats["png_size"] += size + elif item.is_dir(): + stats["folder_count"] += 1 + + return stats + + +def format_file_size(size_bytes: int) -> str: + """ + Format file size in human readable format. + + Args: + size_bytes: Size in bytes + + Returns: + Formatted size string + """ + if size_bytes == 0: + return "0 B" + + size_names = ["B", "KB", "MB", "GB", "TB"] + size = float(size_bytes) + i = 0 + while size >= 1024 and i < len(size_names) - 1: + size /= 1024 + i += 1 + + return f"{size:.1f} {size_names[i]}" + + def main() -> None: """ Main entry point for gallery generation. @@ -206,6 +276,15 @@ def main() -> None: "png_href": png_name }] + # Calculate statistics for single file + current_stats = calculate_directory_stats(source_web_dir) + stats = { + "file_count": 1, + "folder_count": 0, + "total_size": format_file_size(current_stats["total_size"]), + "total_size_bytes": current_stats["total_size"] + } + output_html = source_web_dir / "index.html" with output_html.open("w") as f: f.write(template.render( @@ -213,7 +292,8 @@ def main() -> None: items=items, subdirs=[], relpath=source.name, - ui=CONFIG.ui + ui=CONFIG.ui, + stats=stats )) print(f"Generated {output_html}") diff --git a/template.html b/template.html index d46ee3c..cebcfe1 100644 --- a/template.html +++ b/template.html @@ -278,6 +278,18 @@ text-decoration: none; } + .grid-item.highlighted { + border-color: var(--button-bg); + box-shadow: 0 0 15px rgba(0, 120, 212, 0.3); + transform: translateY(-2px); + animation: highlightPulse 2s ease-in-out; + } + + @keyframes highlightPulse { + 0%, 100% { transform: translateY(-2px) scale(1); } + 50% { transform: translateY(-2px) scale(1.02); } + } + .plot-name { margin-top: 0.8rem; word-wrap: break-word; @@ -509,6 +521,47 @@ font-weight: 500; } + /* ======================================== + GALLERY STATISTICS + ======================================== */ + .gallery-stats { + position: fixed; + bottom: 20px; + left: 20px; + background: var(--card-bg); + border: 1px solid var(--border-color); + border-radius: 8px; + padding: 0.8rem 1rem; + font-size: 0.85rem; + color: var(--breadcrumb-color); + box-shadow: 0 2px 8px rgba(0,0,0,0.1); + z-index: 500; + opacity: 0.8; + transition: opacity 0.2s ease; + max-width: 200px; + } + + .gallery-stats:hover { + opacity: 1; + } + + .stats-item { + display: flex; + justify-content: space-between; + align-items: center; + margin: 0.2rem 0; + white-space: nowrap; + } + + .stats-label { + margin-right: 0.8rem; + } + + .stats-value { + font-weight: 600; + color: var(--text-color); + } + /* ======================================== SUBDIRECTORIES LIST ======================================== */ @@ -583,9 +636,6 @@ + + +