2009-01-22 01:23:20 -07:00
|
|
|
fn conf_enable_blog {
|
2009-01-23 08:44:42 -07:00
|
|
|
blagh_uri=$conf_wd
|
2009-01-22 01:23:20 -07:00
|
|
|
blagh_dirs=$*
|
|
|
|
if(~ $#blagh_dirs 0)
|
2009-01-23 08:44:42 -07:00
|
|
|
blagh_dirs=( . )
|
2009-01-22 01:23:20 -07:00
|
|
|
}
|
|
|
|
|
2008-12-28 03:51:03 -07:00
|
|
|
fn blagh_init {
|
2009-01-23 08:44:42 -07:00
|
|
|
if(~ $#blagh_dirs 0 && ~ $req_path */[bB]log/) {
|
|
|
|
blagh_uri=$req_path
|
|
|
|
blagh_dirs=( . )
|
|
|
|
}
|
2008-12-28 03:51:03 -07:00
|
|
|
|
|
|
|
# Should not match sub-dirs!
|
2009-01-23 08:44:42 -07:00
|
|
|
if(! ~ $#blagh_dirs 0) {
|
|
|
|
# && test -d / `{echo '-a -d '^$blagh_root^$blagh_dirs}
|
|
|
|
blagh_url=$base_url^$blagh_uri
|
2008-12-28 13:37:03 -07:00
|
|
|
blagh_root=$sitedir^$blagh_uri
|
2008-12-28 03:51:03 -07:00
|
|
|
|
2009-01-23 08:44:42 -07:00
|
|
|
if(~ $req_path */ && ~ $req_path $blagh_uri) {
|
2009-01-10 20:40:40 -07:00
|
|
|
handler_body_main=blagh_body
|
2008-12-28 13:37:03 -07:00
|
|
|
u=$blagh_uri'index'
|
2008-12-28 03:51:03 -07:00
|
|
|
extraHeaders=$"extraHeaders ^ \
|
2008-12-28 13:37:03 -07:00
|
|
|
'<link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" />
|
|
|
|
<link rel="alternate" type="application/atom+xml" title="ATOM" href="'$"u'.atom" />'
|
2008-12-28 03:51:03 -07:00
|
|
|
|
|
|
|
}
|
2009-01-12 19:19:45 -07:00
|
|
|
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
|
2008-12-28 03:51:03 -07:00
|
|
|
}
|
2008-12-24 04:19:06 -07:00
|
|
|
}
|
|
|
|
|
2009-01-12 19:19:45 -07:00
|
|
|
fn blagh_setup_feed_handlers {
|
|
|
|
handler_body_main=NOT_USED_by_blagh_feeds
|
|
|
|
res_tail=()
|
|
|
|
master_template=_apps/blagh/$1
|
|
|
|
}
|
|
|
|
|
2008-12-24 04:19:06 -07:00
|
|
|
fn blagh_body {
|
2009-01-23 08:44:42 -07:00
|
|
|
for(p in `{get_post_list $blagh_root^$blagh_dirs}) {
|
2008-12-28 13:37:03 -07:00
|
|
|
l=`{echo -n $p|sed 's!'$sitedir^$req_path'!!'}
|
|
|
|
sed '1s!.*![&]('$l')!' < $p/index.md | $formatter
|
|
|
|
}
|
2008-12-24 04:19:06 -07:00
|
|
|
}
|
|
|
|
|
2008-12-28 13:37:03 -07:00
|
|
|
fn get_post_list {
|
2009-01-02 08:49:44 -07:00
|
|
|
# the /./->/|/ are added so we can sort -t| and order only the file name
|
2009-01-23 08:44:42 -07:00
|
|
|
# NOTE: this breaks if any path element in blagh_dirs contain '/./' or '|'
|
2009-01-12 19:19:45 -07:00
|
|
|
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,/+\|/+,/,'
|
2008-12-24 04:19:06 -07:00
|
|
|
}
|
2009-01-11 18:07:31 -07:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|