Bash script per poter navigare nelle cartelle dentro Public (Dropbox) #3

Nel terzo aggiornamento (vedi precedente) dello script di BASH, ridenominato build-static-index.sh, ho deciso di rendere gradevole la navigazione dell’albero delle directory con un poco di CSS ed un paio di icone.

#!/bin/bash
dropboxpublic="http://dl.dropbox.com/u/12345678"
indexname="index.html"
# one parameter only "directory"
if [ $# -ne 1 ]; then
	echo "Usage: >sh $0 directory"
	exit
fi
#'find' creates the list of subdirectories
for dir in $(find $1 -type d -print); do
	htmlfile="$dir/$indexname"
	echo $htmlfile
	#remove the index if already exists
	if [ -e $htmlfile ]; then
 		rm $htmlfile
	fi
	#create HTML page with files inside directory
	echo -e "<html>\n<head>\n" >> $htmlfile
    echo -e "<title>$dir</title>\n" >> $htmlfile
    echo -e "<link rel=\"stylesheet\" type=\"text/css\" href=\"$dropboxpublic/web/public.css\" />" >> $htmlfile
    echo -e "</head>\n<body>\n" >> $htmlfile

	for file in $( ls $dir -N ); do
		if [ $file != $indexname ]; then
			if [ -d "$dir$file" ]; then
				item="$dropboxpublic/$dir$file/$indexname"
				echo "<li class=\"dir\"><a href=\"$item\">$file</a></li>" >> $htmlfile
			else
				item="$dropboxpublic/$dir/$file"
				echo "<li class=\"file\"><a href=\"$item\">$file</a></li>" >> $htmlfile
			fi

		fi
	done
	echo -e "\n</body>\n</html>" >> $htmlfile
done 

E di seguito anche il CSS relativo:

li {
    line-height: 36px;
    padding-left: 40px;
    list-style-type: none;
}
li.dir {
    background:url(dir.png) center left no-repeat;
}
li.file {
    background:url(file.png) center left no-repeat;
}
li:nth-child(4n)      { background-color:#F7F7F7; }
li:nth-child(4n+1)    { background-color:#DDDDDD; }
li:nth-child(4n+2)    { background-color:#F7F7F7; }
li:nth-child(4n+3)    { background-color:#FFffff; }

Le icone sono PNG 32×32 pixel posizionate in una cartella web figlia della cartella Public.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *