shithub: werc

ref: cf074093fbb7535178428ecff8b8648305cdf216
dir: /apps/blagh/app.rc/

View raw version
fn blagh_init {
    if(~ $#blaghDirs 0 && ~ $req_path */[bB]log/index)
        blaghDirs=( . )

    # Should not match sub-dirs!
    if(! ~ $#blaghDirs 0) {
    # && test -d / `{echo '-a -d '^$req_path^$blaghDirs}

        if(~ $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]/*)
            status='Use default handler'

        if not if(~ $req_path */index) {
            app_body_handler='blagh_body'
            #u=`{cleanname $baseuri^`{basename -d '/'^$uri}|sed 's,:/,://,'} # Sed recovers '/' in 'http:/' stripped by cleanname
            u=`{cleanname $baseuri^$req_path'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)
            app_body_handler='blagh_body'
        if not if(~ $req_path */index.rss)
            app_body_handler='blagh_body'

    }
}

fn blagh_body {
    d=$sitedir$req_path^$blaghDirs^/./[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/ 
    posts=`{ls  -F $d >[2]/dev/null | sed -n 's,/\./,/|/,; /\/$/p' | sort -r '-t|' +1 | sed 's,/+\|/+,/,'}
    for(p in $posts)
        show_post $p | $formatter 
}

fn show_post {
    l=`{echo $1 | sed 's|'$sitedir$req_path'||'}
    sed '1s|.*|[&]('$l')|' < $1/index.md  
}