summaryrefslogtreecommitdiff
path: root/bin/aux/bpst.rc
blob: e60d03416256973848b864604a7c35ca79d76aca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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!