/!/bin/ksh #### CONFIG db=~/imgram wroot=/var/www/htdocs/mywebsite.su/imgram posts_per_page=20 title="imgram gallery" url=https://mywebsite.su desc="flow like a tape" rss_title="$title" rss_url=$url/img.xml rss_path=$wroot/img.xml css=img.css author="you" #If you want to use ImageMagick to convert the images, edit this function #and comment out the #cp $file $wroot/$id.$ext #the example will resize the image file to 860 pixels and convert to jpg. conv() { #ext=jpg # convert -resize 860 $file $wroot/$id.$ext cp $file $wroot/$id.$ext } #edit the following html block from `' to `', do NOT remove #the function `alltags' and `cat tomake'. The various variables change #dynamically depending on what tag and page is being built. This html #block is used for every imgram page: html() { title cat < $page_title stolen image file icon

/ $page_title p$page

$(alltags) $(cat $tomake) eof } ##### END OF CONFIG reverse() { perl -e 'print reverse <>'; } id_gen() { head -n15 /dev/urandom | tr -dc [:lower:] | tail -c6; } #FREEBSD FIX #id_gen() { head -n15 /dev/urandom | LC_CTYPE=C tr -dc [:lower:] | tail -c6; } id_ck() { id=$(id_gen) until [ ! -f $wroot/$id* ]; do print "conflicting id, rehashing" id=$(id_gen) done } cold_start() { [ -f $1 ] && [[ $(file $1 2>/dev/null) = *image* ]] && file=$1 || { print "bad file" && exit; } case $2 in "")tags=no_context;; *)shift; tags="$*";; esac ext=$(print $file | rev | cut -d"." -f1 | rev) id_ck date=$(date +%s) print file: $file print ext: $ext print tags: $tags print id: $id print root: $wroot conv print "$date|$id.$ext|$tags" >> $db/db post >> $db/all for i in $tags; do post >> $db/$i grep -e "$i" $db/alltags || rebuild=1 done if [[ $rebuild = 1 ]]; then print "new tag, rebuilding everything" rebuild else build all build $tags fi rss_feed } build() { for i in $*; do from=1 page=1 end=0 to=$posts_per_page cat $db/$i | reverse > $db/rev file=$db/rev until [[ $end = 1 ]]; do print "making page for tag $i" print "for posts from $from to $to" sed -n "$from , $to p" $db/rev > $db/tmp number $i pager >> $db/tmp tomake=$db/tmp html > $wroot/$out ((page++));from=$((from+posts_per_page)); to=$((to+posts_per_page)) if [[ $(sed -n "$((from)) p" $db/$i) = "" ]]; then end=1 fi done done } alltags() { print "

" for i in $(cat $db/alltags); do print "$i " done print "


" } rebuild() { cd $db for i in * ; do if [[ $i != db && $i != rss ]]; then :> $i fi done while read line; do id=$(print $line | cut -d"|" -f2 | cut -d"." -f1) ext=$(print $line | cut -d"|" -f2 | cut -d"." -f2) date=$(print $line | cut -d"|" -f1) tags=$(print $line | cut -d"|" -f3) post >> $db/all for i in $tags; do post >> $db/$i print $i >> $db/tmptags done done < $db/db cat $db/tmptags | sort | uniq > $db/alltags build $(cat $db/alltags) build all } number() { case $1 in all) if [[ $page = 1 ]]; then out=index.html else out=$page.html fi;; *) if [[ $page = 1 ]]; then out=$1.html else out=$1$page.html fi;; esac } pager() { print "" } title() { if [[ $i = all ]]; then page_title=$title else page_title="$title $i" fi } post() { cat <$id.$ext

$(post_tags)

$date


eof } post_tags() { for i in $tags; do if [[ $rss = 1 ]]; then printf "%s " "$i " else printf "%s " "$i" fi done } rss() { cat < $rss_title $url $desc en-US $(cat $db/rss) eof } rss_item() { rss=1 cat < $id $url/$id.$ext $url/$id.$ext $date

$tags

$(post_tags)

]]>
$(date -u +"%a, %d %h %Y %H:%M:%S +0000") eof } rerss() { :>$db/rss cat $db/db | tail -n 20 | reverse > $db/tmp while read line; do id=$(print $line | cut -d"|" -f2 | cut -d"." -f1) ext=$(print $line | cut -d"|" -f2 | cut -d"." -f2) date=$(print $line | cut -d"|" -f1) tags=$(print $line | cut -d"|" -f3) rss_item >> $db/rss done < $db/tmp rss > $rss_path } rss_feed() { rss_item > $db/tmp cat $db/rss >> $db/tmp cat $db/tmp > $db/rss rss > $rss_path } if [[ $1 = rebuild ]]; then rebuild; exit; fi if [[ $1 = rss ]]; then rerss; exit; fi cold_start $*