#!/bin/bash
printf "\nRepo page : photo gallery - licence GPL - marnout à free fr\n"
if [[ ! $# -eq 1 ]]; then printf "Usage\n$0 page\n"; exit 1; fi
page=$1 # folder number to process
wd=img/$page # folder to process
# did $wd exist ?
if [[ ! -d $wd ]]; then echo $wd not found, abort; exit 2; fi
# images count
count=`ls -l img | grep "^d" | wc -l`
# write $page.html
dest=$page.html # destination file to write
printf "\nWriting $dest\n"
# common header
cat > $dest << Header
Pistou
Cliquer sur une image pour l'agrandir
[Back space] ou [Alt ←] pour revenir.
Site réalisé en script bash repo
Header
# navigation
printf " \n" >> $dest
p=$count
while [ $p -gt 0 ]
do
[ $p == $page ] &&
li=" $p \n" ||
li=" $p \n"
printf "$li" >> $dest
let p--
done
# add this page to other pages menus
p=1
li=" $page "
while [ $p -lt $count ]
#for p in {1..$count}
do
if [[ -z `grep "$page.html" $p.html` ]]
then
sed -i "/$(($page - 1)).html/i\ $li" $p.html
fi
let p++
done
# close nav
printf " \n" >> $dest
# draw boxes
for im in `ls -v $wd/*.jpg`
do
date=`getexif d $im`
comment=`exiv2 -p c $im`
printf "\n" >> $dest
printf "
\n" >> $dest
printf "
$comment
\n" >> $dest
printf "
\n" >> $dest
printf "`basename $im` $comment\n"
done
# end
printf "" >> $dest