From fdade23cfa14451ecdb9ed4914589cfc0e3aa333 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 16 May 2020 14:33:29 +0200 Subject: Fix sort order of Blog posts in procmail.sh --- TODO | 1 + plugins/weblog/procmail/procmail.sh | 30 +++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 4bbcf92..7072663 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,5 @@ git via smart http / cgi +git via web interface php weblog: link consistency check (cron?) Integrate into Debian: WNPP diff --git a/plugins/weblog/procmail/procmail.sh b/plugins/weblog/procmail/procmail.sh index 44fa68f..473ff8e 100755 --- a/plugins/weblog/procmail/procmail.sh +++ b/plugins/weblog/procmail/procmail.sh @@ -17,9 +17,29 @@ function mimedecode() { perl -ne 'require MIME::Head; $head = MIME::Head->read(\*STDIN); $head->decode(); print $head->get("Subject")' } +function next_index() { + DIR=$1 + + LASTENTRY=`ls -1r $DIR/$(date +%Y)/$(date +%Y%m%d)* 2>/dev/null | xargs -n 1 basename | head -n1` + + if [ "$LASTENTRY" == "" ] ; then + echo 001 + return + fi + + INDEX=${LASTENTRY:9:3} + + INDEX=$(($INDEX + 2)) + + while [ "$((${#INDEX} < 3))" == "1" ] ; do INDEX=0$INDEX ; done + + echo $INDEX +} + echo "Log at `date`:" >> ~/log 2>&1 -BLOGDIR=/var/www/blog +BLOGDIR=/var/www/rolandreichwein.de-blog +#BLOGDIR=/var/www/blog # Default: Error ERRORMSG="General error." @@ -64,8 +84,9 @@ echo "$BODY" > /home/weblog-bloginput/body.txt SUBJECT=`echo "$HEADER" | mimedecode` SUBJECT_PATH=`echo "$SUBJECT" | sed -e 's/[^a-zA-Z0-9]/_/g'` +ARTICLEINDEX=`next_index $BLOGDIR` -ARTICLEDIR="$BLOGDIR/`date +%Y/%Y%m%d`_$SUBJECT_PATH" +ARTICLEDIR="$BLOGDIR/`date +%Y/%Y%m%d`_${ARTICLEINDEX}_$SUBJECT_PATH" mkdir -p $ARTICLEDIR echo "Subject: $SUBJECT" >> $ARTICLEDIR/article.data @@ -85,7 +106,10 @@ fi chmod -R a+r $ARTICLEDIR chmod a+x $ARTICLEDIR -echo "Processed successfully." | mutt -s "Bloginput: $SUBJECT_PATH" -- "$ADDR" >> ~/log 2>&1 +( +echo "Processed successfully." +echo "ARTICLEDIR=$ARTICLEDIR" +) | mutt -s "Bloginput: $SUBJECT_PATH" -- "$ADDR" >> ~/log 2>&1 echo "User log:" >> ~/log cat body.txt >> ~/log -- cgit v1.2.3