Move blagh feed templates to app dir, be smarter when enabling 'implicit' blogs, and upgrade the web interface for blog posting.

This commit is contained in:
Uriel 2009-01-25 16:52:19 +01:00
parent f795f9e1d3
commit 5755022405
3 changed files with 251 additions and 30 deletions

View file

@ -6,8 +6,8 @@ fn conf_enable_blog {
}
fn blagh_init {
if(~ $#blagh_dirs 0 && ~ $req_path */[bB]log/) {
blagh_uri=$req_path
if(~ $#blagh_dirs 0 && ~ $req_path */[bB]log/*) {
blagh_uri=`{echo $req_path | sed 's,(/[bB]log/).*,\1,'}
blagh_dirs=( . )
}
@ -16,26 +16,40 @@ fn blagh_init {
# && test -d / `{echo '-a -d '^$blagh_root^$blagh_dirs}
blagh_url=$base_url^$blagh_uri
blagh_root=$sitedir^$blagh_uri
if(check_user $blog_editors admin) {
editor_mode=on
ll_add handlers_bar_left echo '<a href="'$blagh_uri'new_post">Make a new post</a>'
}
if(~ $req_path */ && ~ $req_path $blagh_uri) {
switch($req_path) {
case $blagh_uri
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/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)
case $blagh_uri^index.atom
blagh_setup_feed_handlers atom.tpl
if not if(~ $req_path */index.rss)
case $blagh_uri^index.rss
blagh_setup_feed_handlers rss20.tpl
case $blagh_uri^new_post
if(! ~ $#editor_mode 0) {
if(~ $REQUEST_METHOD GET)
handler_body_main=( tpl_handler `{get_lib_file blagh/new_post.tpl apps/blagh/new_post.tpl} )
if not if(~ $REQUEST_METHOD POST) {
mkbpost $post_arg_id $post_arg_title $post_arg_body
post_redirect $blagh_uri
}
}
}
}
}
fn blagh_setup_feed_handlers {
handler_body_main=NOT_USED_by_blagh_feeds
res_tail=()
master_template=_apps/blagh/$1
master_template=apps/blagh/$1 # Should we allow tempalte override?
}
fn blagh_body {
@ -46,30 +60,35 @@ fn blagh_body {
}
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 blagh_dirs contain '/./' or '|'
# /./->/|/ done to sort -t| and order by date
# Note: $paths in blagh_dirs should not 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
fn mkbpost {
if(! ~ 0 $#1 $#2) {
umask 002 # Let group write
bptitle=$1
bptext=$2
if(! ~ $#3 0)
bpid=`{echo -n '-'^$"bpid | sed 's/'$forbidden_uri_chars'+/_/g; 1q'}
d=`{/bin/date +%F|sed 's,-,/,g'}
ddir=$blagh_root^$d^'/'
n=`{ls $ddir >[2]/dev/null |wc -l}
mkdir -p $ddir/$"n^$"bpid/
{
echo $bptitle
echo '========================================='
# TODO: Enable metadata
#echo '* Posted:' `{date}
#if(! ~ $#logged_user 0)
# echo '* Author: '$logged_user
echo
echo $bptext
}> $ddir/$"n^$"bpid/index.md
}
if not
status=Missing blog post arguments $"1 $"2 $"3
status=Missing blog post arguments $"1 $"2
}