#!/usr/bin/env bash # # Author: Lilian BESSON # Email: Lilian.BESSON[AT]ens-cachan[DOT]fr # Date: 16/06/2017 # Web version: http://perso.crans.org/besson/bin/generateglisse.sh # Web version (2): https://bitbucket.org/lbesson/bin/src/master/generateglisse.sh # # Auto generate an 'index.html' page to show photos with glisse.js # Also generate a 'index.htm' page, which works on Windows by fetching the CSS and JS online (http://perso.crans.org/besson/_static/) and not locally (http://0.0.0.0/). # # FUTURE: use http://dimsemenov.com/plugins/magnific-popup/documentation.html#gallery instead, seems better. # # A demo is here : http://perso.crans.org/besson/generateglisse.sh/ # Last version is here : http://perso.crans.org/besson/bin/generateglisse.sh # with stylesheets and templates is here : http://perso.crans.org/besson/bin/generateglisse/ # version='1.1' GenerateGlisse() { # Go to the directory. p=$(pwd) if [ -d "$*" ]; then cd "$*"; fi echo -e "Working for the directory ${magenta}$(pwd)${white}." # if [ -f index.html ]; then # cp -vf index.html $(tempfile) # mv -f index.html index.html~ # fi # Header currentdir="$(basename "$(pwd -P)")" currentdir="${currentdir#./}" cat ~/bin/generateglisse/header.html \ | sed s%VERSION%"$version"% \ | sed s%CURRENTDIR%"$currentdir"% \ | sed s%VERSION%"$version"% \ | sed s_DATE_"$(date +" %d %b %Y, à %Hh:%Mm:%Ss")"_ > index.html # Listing of sub directories (without .. ou .) targets=$(find . -maxdepth 1 -type d -iname '*'[A-Za-z]'*' 2>/dev/null) targets=${targets//' '/%20} targets="${targets//'&'/&}" echo -e "$red$targets$white" > /dev/stderr if [ "X$targets" != "X" ]; then nombre=$(echo "$targets" | grep -c -o ./) if (( nombre > 1 )); then echo -e "

Liste des sous-dossiers (au nombre de $nombre) :

" >> index.html else echo -e "

Liste du sous-dossier :

" >> index.html fi echo -e "
    " >> index.html echo -e "
  • .. (dossier parent)
  • " >> index.html for d in $targets; do dossier=${d//'%20'/ } dossier=${dossier//'&'/&} subphotos=$(find "${dossier}" -maxdepth 1 -type f -iname '*'.jpg -o -iname '*'.png -o -iname '*'.gif -o -iname '*'.jpeg 2>/dev/null) nombrephotos=$(echo "$subphotos" | grep -c -o "\(jpg\|JPG\|png\|PNG\|gif\|GIF\|jpeg\|JPEG\)") subdirs=$(find "${dossier}" -maxdepth 1 -type d -iname '*'[A-Za-z]'*' 2>/dev/null) nombredirs=$(echo "$subdirs" | grep -c -o ./) nombredirs=$(( nombredirs / 2 )) # does not count itself ? FIXME # Adapt what to print according to the number of subdirs and photos if (( nombrephotos > 1 )); then if (( nombredirs > 1 )); then echo -e "
  • ${dossier} (${nombrephotos} photos, ${nombredirs} sous-dossiers)
  • " >> index.html elif (( nombredirs == 1 )); then echo -e "
  • ${dossier} (${nombrephotos} photos, 1 sous-dossier)
  • " >> index.html else echo -e "
  • ${dossier} (${nombrephotos} photos)
  • " >> index.html fi elif (( nombrephotos == 1 )); then if (( nombredirs > 1 )); then echo -e "
  • ${dossier} (1 photo, ${nombredirs} sous-dossiers)
  • " >> index.html elif (( nombredirs == 1 )); then echo -e "
  • ${dossier} (1 photo, 1 sous-dossier)
  • " >> index.html else echo -e "
  • ${dossier} (1 photo)
  • " >> index.html fi else if (( nombredirs > 1 )); then echo -e "
  • ${dossier} (${nombredirs} sous-dossiers)
  • " >> index.html elif (( nombredirs == 1 )); then echo -e "
  • ${dossier} (1 sous-dossier)
  • " >> index.html fi fi echo -e "For ${u}${dossier}${U}: ${yellow}${nombrephotos}${white} photos, ${magenta}${nombredirs}${white} subdirs." done echo -e "



" >> index.html fi # Listing of photos (and gallery) (with glisse.js) targets=$(find . -maxdepth 1 -type f -iname '*'.jpg -o -iname '*'.png -o -iname '*'.gif -o -iname '*'.jpeg 2>/dev/null) if [ "X${targets//'%20'/}" != "X" ]; then targets="${targets//' '/%20}" targets="${targets//'&'/&}" nombre=$(echo "$targets" | grep -c -o "\(jpg\|JPG\|png\|PNG\|gif\|GIF\|jpeg\|JPEG\)") # Print the list of files. if (( nombre > 1 )); then echo -e "

Liste des photos (au nombre de $nombre) :

" >> index.html else echo -e "

Une seule photo :

" >> index.html fi # I prefer to use the gallery style, it is REALLY better than the stack one (and less cpu consuming) echo -e "