#!/usr/bin/env bash # MIT License # Copyright (c) 2022 Angel Jumbo # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. generate_thumbnails() { echo "generate thumbnails ..." mkdir -p thumbnails rm -rf thumbnails/* # Count total number of images total_images=$(find ./wallpapers -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" \) | wc -l) current_image=0 for section_dir in ./wallpapers/*; do section_name="${section_dir##*/}" mkdir -p "thumbnails/$section_name" # Process dark images (base directory) for img in "$section_dir"/*; do [ -f "$img" ] || continue case "$img" in *.jpg|*.jpeg|*.png|*.JPG|*.JPEG|*.PNG) ;; *) continue ;; esac current_image=$((current_image + 1)) local img_filename="${img##*/}" local thumbnail="thumbnails/$section_name/$img_filename" echo "($current_image/$total_images): $img -> $thumbnail" convert "$img" -resize 300x300 "$thumbnail" done # Process light images if light folder exists if [ -d "$section_dir/light" ]; then mkdir -p "thumbnails/$section_name/light" for img in "$section_dir/light"/*; do [ -f "$img" ] || continue case "$img" in *.jpg|*.jpeg|*.png|*.JPG|*.JPEG|*.PNG) ;; *) continue ;; esac current_image=$((current_image + 1)) local img_filename="${img##*/}" local thumbnail="thumbnails/$section_name/light/$img_filename" echo "($current_image/$total_images): $img -> $thumbnail" convert "$img" -resize 300x300 "$thumbnail" done fi done echo "Thumbnail generation complete: $total_images images processed" } check_has_light_folder() { local section_dir=$1 [ -d "$section_dir/light" ] && echo "true" || echo "false" } count_images_in_dir() { local dir=$1 find "$dir" -maxdepth 1 -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" \) | wc -l } create_section_data() { local section=$1 local subdir=$2 local maxPerPage=8 local has_light=$(check_has_light_folder "$subdir") echo "Creating data for section: $section" # Create JSON data file for the section local data_file="${section}_data.js" cat > "$data_file" << EOF // Data for $section section window.sectionData = window.sectionData || {}; window.sectionData['$section'] = { hasLight: $has_light, maxPerPage: $maxPerPage, dark: [ EOF # Generate dark images data for wallpaper in "$subdir"/*; do [ -f "$wallpaper" ] || continue case "$wallpaper" in *.jpg|*.jpeg|*.png|*.JPG|*.JPEG|*.PNG) ;; *) continue ;; esac local img_path="${wallpaper#./}" local img_filename="${wallpaper##*/}" local thumbnail_path="thumbnails/$section/$img_filename" echo " { src: '$img_path', thumb: '$thumbnail_path', alt: '$img_filename' }," >> "$data_file" done # Generate light images data if exists echo " ]," >> "$data_file" if [ "$has_light" = "true" ]; then echo " light: [" >> "$data_file" for wallpaper in "$subdir/light"/*; do [ -f "$wallpaper" ] || continue case "$wallpaper" in *.jpg|*.jpeg|*.png|*.JPG|*.JPEG|*.PNG) ;; *) continue ;; esac local img_path="${wallpaper#./}" local img_filename="${wallpaper##*/}" local thumbnail_path="thumbnails/$section/light/$img_filename" echo " { src: '$img_path', thumb: '$thumbnail_path', alt: '$img_filename' }," >> "$data_file" done echo " ]" >> "$data_file" else echo " light: []" >> "$data_file" fi echo "};" >> "$data_file" } # Clean up old files rm -f *.html *.js # Generate thumbnails generate_thumbnails # Create main index.html cat > index.html << 'EOF' Gruvbox wallpapers

Gruvbox Wallpapers

EOF # Generate sections color=1 declare -a sections declare -a sections_with_light for subdir in ./wallpapers/*; do section="${subdir##*/}" sections+=("$section") has_light=$(check_has_light_folder "$subdir") if [ "$has_light" = "true" ]; then sections_with_light+=("$section") fi # Create the data file create_section_data "$section" "$subdir" # Add section to main page echo "

" >> index.html echo " $(echo "$section" | tr a-z A-Z)" >> index.html echo "

" >> index.html echo "
" >> index.html # Add theme switcher if section has light variant if [ "$has_light" = "true" ]; then echo "
" >> index.html echo "
" >> index.html echo " " >> index.html echo " " >> index.html echo "
" >> index.html echo "
" >> index.html fi echo "
" >> index.html echo "
Loading...
" >> index.html echo "
" >> index.html echo "
" >> index.html color=$((color + 1)) if [ "$color" -eq 8 ]; then color=1 fi done # Add all section data scripts for section in "${sections[@]}"; do echo " " >> index.html done # Add main JavaScript cat >> index.html << 'EOF' EOF echo "Build complete! Generated $(echo ${#sections[@]}) sections with dynamic content loading." echo "Sections with light variants: ${sections_with_light[*]}"