summaryrefslogtreecommitdiff
path: root/bin/aux/bpst.rc
diff options
context:
space:
mode:
Diffstat (limited to 'bin/aux/bpst.rc')
-rwxr-xr-xbin/aux/bpst.rc64
1 files changed, 64 insertions, 0 deletions
diff --git a/bin/aux/bpst.rc b/bin/aux/bpst.rc
new file mode 100755
index 0000000..e60d034
--- /dev/null
+++ b/bin/aux/bpst.rc
@@ -0,0 +1,64 @@
+#!/bin/rc
+
+path=( $PLAN9/bin $path )
+base=.
+
+if(~ $#user 0)
+ user=`{whoami}
+
+file=(); title=();
+bloguser=$user
+while(! ~ $#* 0) {
+ switch($1) {
+ case -u
+ base=/gsoc/www/people/$user/blog/
+ case -b
+ shift
+ base=$1
+ case -f
+ shift
+ file=$1
+ }
+ shift
+}
+
+if(~ $"EDITOR '')
+ EDITOR=vi
+
+if(~ $#file 0 || ! test -f $file) {
+ file=/tmp/blogtmp.$pid
+ rm $file >[2]/dev/null
+ touch $file
+}
+
+$EDITOR $file
+ispell $file
+rm $file.bak >[2]/dev/null
+
+fn mkbpost {
+ umask 002 # Let group write
+ bptext=$1
+ if(! ~ $#2 0)
+ bpid=`{echo -n '-'^$"bpid | sed 's/'$forbidden_uri_chars'+/_/g; 1q'}
+ d=`{/bin/date +%F|sed 's,-,/,g'}
+
+ ddir=$blagh_root^$d^'/'
+ n=`{ls $ddir >[2]/dev/null |wc -l}
+
+ mkdir -p $ddir/$"n^$"bpid/
+ {
+ # TODO: Enable metadata
+ #echo '* Posted:' `{date}
+ #if(! ~ $#logged_user 0)
+ # echo '* Author: '$logged_user
+ cat $bptext
+ }> $ddir/$"n^$"bpid/index.md
+}
+
+forbidden_uri_chars='[^a-zA-Z0-9_+\-\/\.]'
+blagh_root=$base
+
+if(test -s $file)
+ mkbpost $file
+if not
+ echo Empty file!