summaryrefslogtreecommitdiffhomepage
path: root/plugins/weblog/procmail
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-05-16 14:33:29 +0200
committerRoland Reichwein <mail@reichwein.it>2020-05-16 14:33:29 +0200
commitfdade23cfa14451ecdb9ed4914589cfc0e3aa333 (patch)
treebaebdc0a9436120201534b83060abb3d3dd5002b /plugins/weblog/procmail
parent6b2a9dabbfad4d64268967a32dff0f1dc55763de (diff)
Fix sort order of Blog posts in procmail.sh
Diffstat (limited to 'plugins/weblog/procmail')
-rwxr-xr-xplugins/weblog/procmail/procmail.sh30
1 files changed, 27 insertions, 3 deletions
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