shithub: werc

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

View raw version
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

        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=$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 {
            response_format=raw
            if(~ $req_path */index.atom)
                master_template=_apps/blagh/atom.tpl
            if not if(~ $req_path */index.rss)
                master_template=_apps/blagh/rss20.tpl
        }
    }
}

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 's,/\./,/|/,; /\/$/p' | sort -r '-t|' +1 | sed 's,/+\|/+,/,'
}