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-02-07 17:22:46 -07:00
|
|
|
conf_enable_app blagh
|
2009-06-12 15:59:47 -06:00
|
|
|
|
|
|
|
if(~ $"conf_blog_editors '')
|
|
|
|
conf_blog_editors=blog-editors
|
|
|
|
|
|
|
|
if(~ $"conf_max_posts_per_page '')
|
|
|
|
conf_max_posts_per_page=32
|
2009-01-22 01:23:20 -07:00
|
|
|
}
|
|
|
|
|
2008-12-28 03:51:03 -07:00
|
|
|
fn blagh_init {
|
2009-01-25 08:52:19 -07:00
|
|
|
if(~ $#blagh_dirs 0 && ~ $req_path */[bB]log/*) {
|
|
|
|
blagh_uri=`{echo $req_path | sed 's,(/[bB]log/).*,\1,'}
|
2009-01-23 08:44:42 -07:00
|
|
|
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
|
2009-02-28 06:26:40 -07:00
|
|
|
if(check_user $conf_blog_editors) {
|
2009-01-25 08:52:19 -07:00
|
|
|
editor_mode=on
|
2009-02-13 16:21:15 -07:00
|
|
|
if(~ $"post_arg_date '')
|
|
|
|
post_date=`{/bin/date +%F|sed 's,-,/,g'}
|
|
|
|
if not
|
|
|
|
post_date=$post_arg_date
|
2009-01-25 08:52:19 -07:00
|
|
|
ll_add handlers_bar_left echo '<a href="'$blagh_uri'new_post">Make a new post</a>'
|
|
|
|
}
|
2008-12-28 03:51:03 -07:00
|
|
|
|
2009-02-15 19:27:28 -07:00
|
|
|
if(~ $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 ^ \
|
2009-03-05 17:15:26 -07:00
|
|
|
'<link rel="alternate" type="application/atom+xml" title="ATOM" href="'$"u'.atom" />
|
|
|
|
<link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" />'
|
2009-02-15 19:27:28 -07:00
|
|
|
}
|
|
|
|
if not if(~ $req_path $blagh_uri^index.atom)
|
2009-03-13 06:04:25 -06:00
|
|
|
blagh_setup_feed_handlers atom.tpl 'application/atom+xml'
|
2009-02-15 19:27:28 -07:00
|
|
|
|
|
|
|
if not if(~ $req_path $blagh_uri^index.rss)
|
2009-03-13 06:04:25 -06:00
|
|
|
blagh_setup_feed_handlers rss20.tpl 'text/xml; charset=utf-8'
|
2009-02-15 19:27:28 -07:00
|
|
|
|
|
|
|
if not if(~ $req_path $blagh_uri^new_post && ! ~ $#editor_mode 0) {
|
|
|
|
handler_body_main=( tpl_handler `{get_lib_file blagh/new_post.tpl apps/blagh/new_post.tpl} )
|
|
|
|
if(~ $REQUEST_METHOD POST) {
|
|
|
|
if(mkbpost $"post_arg_body $"post_date $"post_arg_title $post_arg_id)
|
|
|
|
post_redirect $blagh_uri
|
|
|
|
if not
|
|
|
|
notify_errors=$status
|
2009-01-25 08:52:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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=()
|
2009-03-13 06:04:25 -06:00
|
|
|
http_content_type=$2
|
2009-02-13 06:23:19 -07:00
|
|
|
headers=()
|
2009-01-25 08:52:19 -07:00
|
|
|
master_template=apps/blagh/$1 # Should we allow tempalte override?
|
2009-01-12 19:19:45 -07:00
|
|
|
}
|
|
|
|
|
2008-12-24 04:19:06 -07:00
|
|
|
fn blagh_body {
|
2009-02-12 15:03:57 -07:00
|
|
|
if (! ~ $"blogTitle '')
|
|
|
|
echo '<h1>'$"blogTitle'</h1>'
|
|
|
|
|
|
|
|
echo '<div style="text-align:right">(<a href="index.rss">RSS Feed</a>|<a href="index.atom">Atom Feed</a>)</div>'
|
|
|
|
|
2009-06-12 15:56:48 -06:00
|
|
|
{ # XXX Not sure why this fixes issues with blog setup, probably bug in fltr_cache!
|
2009-01-23 08:44:42 -07:00
|
|
|
for(p in `{get_post_list $blagh_root^$blagh_dirs}) {
|
2009-02-14 13:34:23 -07:00
|
|
|
l=`{echo -n $p|sed 's!'$sitedir^'/?(.*)([0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9])(/[^/]+/)!\2 /\1\2\3!'}
|
2009-02-01 12:03:27 -07:00
|
|
|
sed '1s!.*![&]('^$l(2)^') ('^$l(1)^')!' < $p/index.md
|
2009-07-14 16:53:23 -06:00
|
|
|
echo # Needed extra \n so markdown doesn't mess up the formatting, probably can be done in sed.
|
2009-06-12 15:56:48 -06:00
|
|
|
}
|
2010-01-18 17:31:55 -07:00
|
|
|
# XXX BUG! Markdown [references] break because multiple markdown documents are merged. Should format each blog post independently.
|
|
|
|
# TODO: use fltr_cache directly, that can fix the previous bug plus provide a perf boost by caching title generation.
|
2009-02-01 12:03:27 -07:00
|
|
|
} | $formatter
|
2008-12-24 04:19:06 -07:00
|
|
|
}
|
|
|
|
|
2008-12-28 13:37:03 -07:00
|
|
|
fn get_post_list {
|
2009-01-25 08:52:19 -07:00
|
|
|
# /./->/|/ done to sort -t| and order by date
|
|
|
|
# Note: $paths in blagh_dirs should not contain '/./' or '|'
|
2009-06-12 15:44:21 -06: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 -e 's,/+\|/+,/,' -e $conf_max_posts_per_page^'q'
|
2008-12-24 04:19:06 -07:00
|
|
|
}
|
2009-01-11 18:07:31 -07:00
|
|
|
|
2009-01-25 08:52:19 -07:00
|
|
|
fn mkbpost {
|
2009-02-13 16:21:15 -07:00
|
|
|
bptext=$1
|
|
|
|
bpdate=$2
|
|
|
|
bptitle=$3
|
|
|
|
bpid=$4
|
|
|
|
_status=()
|
|
|
|
if(~ $"bptext '')
|
|
|
|
_status=($_status 'You need to provide a post body.')
|
|
|
|
if(! ~ $"bpdate [0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9])
|
|
|
|
_status=($_status 'Invalid date: '''^$"bpdate^'''') # XXX Should make semantic check.
|
|
|
|
|
|
|
|
if(~ $#_status 0) {
|
2009-01-25 08:52:19 -07:00
|
|
|
umask 002 # Let group write
|
2009-02-13 16:21:15 -07:00
|
|
|
if(! ~ $"bpid '')
|
|
|
|
bpid=`{echo -n '-'^$bpid | sed 's/'$forbidden_uri_chars'+/_/g; 1q'}
|
2009-01-25 08:52:19 -07:00
|
|
|
|
2009-02-13 16:21:15 -07:00
|
|
|
ddir=$blagh_root^$bpdate^'/'
|
2009-01-25 08:52:19 -07:00
|
|
|
n=`{ls $ddir >[2]/dev/null |wc -l}
|
|
|
|
|
|
|
|
mkdir -p $ddir/$"n^$"bpid/
|
|
|
|
{
|
2009-02-13 16:21:15 -07:00
|
|
|
if(! ~ $"bptitle '') {
|
|
|
|
echo $bptitle
|
|
|
|
echo '========================================='
|
|
|
|
}
|
2009-01-25 08:52:19 -07:00
|
|
|
# TODO: Enable metadata
|
|
|
|
#echo '* Posted:' `{date}
|
|
|
|
#if(! ~ $#logged_user 0)
|
|
|
|
# echo '* Author: '$logged_user
|
|
|
|
echo
|
|
|
|
echo $bptext
|
|
|
|
}> $ddir/$"n^$"bpid/index.md
|
2009-07-18 19:27:26 -06:00
|
|
|
|
2009-07-19 22:01:36 -06:00
|
|
|
# Experimental support for http://pubsubhubbub.googlecode.com/
|
|
|
|
if(! ~ $"conf_blog_pubsubdub_hub '') {
|
|
|
|
ifs='' { p=`{echo $req_url|sed 's/new_post$/index.atom/'|url_encode } }
|
|
|
|
dprint hget -p 'hub.mode=publish&hub.url='^$"p $conf_blog_pubsubdub_hub
|
2009-08-05 19:09:04 -06:00
|
|
|
hget -d -h -p 'hub.mode=publish&hub.url='^$"p $conf_blog_pubsubdub_hub >[1=2] &
|
2009-07-18 19:27:26 -06:00
|
|
|
}
|
2009-01-11 18:07:31 -07:00
|
|
|
}
|
2009-02-13 16:21:15 -07:00
|
|
|
status=$_status
|
2009-01-11 18:07:31 -07:00
|
|
|
}
|
2009-06-13 07:59:43 -06:00
|
|
|
|
|
|
|
fn strip_title_from_md_file {
|
|
|
|
sed '1N; /^.*\n===*$/N; /.*\n===*\n$/d'
|
|
|
|
}
|