ref: a29d7781872bbf1c95a7b297e39526e1a5ce81a7
dir: /apps/blagh/app.rc/
fn blagh_init { if(~ $#blaghDirs 0 && ~ $local_path */[bB]log/index*) blaghDirs=( . ) # Should not match sub-dirs! if(! ~ $#blaghDirs 0) { # && test -d / `{echo '-a -d '^$req_path^$blaghDirs} blagh_uri=`{echo $req_path|sed 's/index(\.(atom|rss))?$//'} blagh_url=$base_uri^$blagh_root_path blagh_root=$sitedir^$blagh_uri # XXX This is a hideous hack, blogs in dirs that match the number patern wont work, and dirs inside posts (eg., comments) wont work either. # The problem is how to find out the 'root' of this blog, blaghDirs is useless for that. if(~ $req_path */ && ! ~ $req_path */[0-9][0-9][0-9][0-9]/ */[0-9][0-9][0-9][0-9]/[0-9][0-9]/ */[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/*) { handler_body_main=blagh_body u=$blagh_uri'index' extraHeaders=$"extraHeaders ^ \ '<link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" /> <link rel="alternate" type="application/atom+xml" title="ATOM" href="'$"u'.atom" />' } if not if(~ $req_path */index.atom) blagh_setup_feed_handlers atom.tpl if not if(~ $req_path */index.rss) blagh_setup_feed_handlers rss20.tpl } } fn blagh_setup_feed_handlers { handler_body_main=NOT_USED_by_blagh_feeds res_tail=() master_template=_apps/blagh/$1 } fn blagh_body { for(p in `{get_post_list $blagh_root^$blaghDirs}) { l=`{echo -n $p|sed 's!'$sitedir^$req_path'!!'} sed '1s!.*![&]('$l')!' < $p/index.md | $formatter } } fn get_post_list { # the /./->/|/ are added so we can sort -t| and order only the file name # NOTE: this breaks if any path element in blogDirs contain '/./' or '|' ls -F $*^/./[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/ >[2]/dev/null | sed -n '/'^$forbidden_uri_chars^'/d; s,/\./,/|/,; /\/$/p' | sort -r '-t|' +1 | sed 's,/+\|/+,/,' } fn make_blog_post { if(! ~ 0 $#1 $#2 $#3) { bdir=$1 btitle=$2 btext=$3 date=`{/bin/date +%F} n=1 for(f in $bdir^$date^'-'*) { i=`{echo -n $f | sed -n 's,^.*/'$date'-([0-9]+)_.*,\1,p'|tr -d $NEW_LINE} if(! ~ $#i 0 && test $i -ge $n) n=`{hoc -e $i'+1'} } btitle=`{echo -n $"btitle | sed 's/[ ]+/_/g; 1q'} echo $btext > $bdir^'/'^$"date^'-'^$"n^_$"btitle.md } if not status=Missing blog post arguments $"1 $"2 $"3 }