From e364bbdde0eb0f45a83aa8266a30907b5be0db92 Mon Sep 17 00:00:00 2001 From: uriel Date: Sun, 25 Jan 2009 16:52:19 +0100 Subject: [PATCH] Move blagh feed templates to app dir, be smarter when enabling 'implicit' blogs, and upgrade the web interface for blog posting. --- apps/blagh/app.rc | 79 ++++++++++++++---------- apps/blagh/atom.tpl | 140 +++++++++++++++++++++++++++++++++++++++++++ apps/blagh/rss20.tpl | 62 +++++++++++++++++++ 3 files changed, 251 insertions(+), 30 deletions(-) create mode 100644 apps/blagh/atom.tpl create mode 100644 apps/blagh/rss20.tpl diff --git a/apps/blagh/app.rc b/apps/blagh/app.rc index 7622007..8e3bbd6 100644 --- a/apps/blagh/app.rc +++ b/apps/blagh/app.rc @@ -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 'Make a new post' + } - if(~ $req_path */ && ~ $req_path $blagh_uri) { + switch($req_path) { + case $blagh_uri handler_body_main=blagh_body u=$blagh_uri'index' extraHeaders=$"extraHeaders ^ \ - ' +' ' - - } - 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 } - diff --git a/apps/blagh/atom.tpl b/apps/blagh/atom.tpl new file mode 100644 index 0000000..2970b81 --- /dev/null +++ b/apps/blagh/atom.tpl @@ -0,0 +1,140 @@ +Content-Type: application/atom+xml + + + + +%{ +fn statpost { + f = $1 + + updated = `{/bin/date --rfc-3339'=seconds' -r $f |tr ' ' 'T'} + post_uri=$base_url^`{cleanname `{echo $f | sed -e 's!^'$sitedir'!!' -e 's/\.(md|tpl)$//g'}} + title=`{read $f/index.md} + # Not used: date=`{/bin/date -Rd `{basename $f |sed 's/(^[0-9\-]*).*/\1/; s/-[0-9]$//'}} + # TODO: use mtime(1) and ls(1) instead of lunix's stat(1) + stat=`{stat -c '%Y %U' $f} + #mdate=`{/bin/date -Rd `{mtime $f|awk '{print $1}' }} # Not used because it is unreliable + by=$stat(2) + ifs=() { summary=`{cat $f/index.md | crop_text 512 ... | $formatter } } +} +updated = `{/bin/date --rfc-3339'=seconds' |sed 's/ /T/'} +%} + + + + + %($req_path%) + /favicon.ico + + %($siteTitle%) + %($siteSubTitle%) + + + %($updated%) + + +%{ + for(f in `{get_post_list $blagh_root$blagh_dirs}) { + statpost $f +%} + + + %($post_uri%) + + %($title%) + + + %($by%) + + + +
+ %($summary%) +
+ + %($updated%) +
+ + +% } + +
+ +% exit + + + + http://intertwingly.net/blog/index.atom + ../favicon.ico + + Sam Ruby + It’s just data + + Sam Ruby + rubys@intertwingly.net + /blog/ + + 2008-09-24T12:47:00-04:00 + + + + + tag:intertwingly.net,2004:2899 + + + RubyConf 2008 +
+ +

My proposal has been accepted for RubyConf 2008.  Because of the presence of Ruby implementers, this is going to be a bit challenging as it will likely turn into two talks at once.  One sharing experiences with fellow developers concerning things they may need to watch out for, and another with language designers about the impact of their changes.  It also is likely to be true, as it was at OSCON, that there will be members of the audience who know way more about this subject than I do.

+

I had originally requested a slot on Saturday.  My current slot requires me to shave a day off of ApacheCon.  I’ve again asked that the slot be changed, but even if it doesn’t move, I can manage this.  At least we are only talking about a short hop from New Orleans to Orlando.

+ +
+ 2008-09-11T06:51:36-04:00 +
+ + + tag:intertwingly.net,2004:2898 + + + Small Updates +
+ +

Alf Eaton: Aside: if you’re reading a Planet that contains HubLog, those posts will all jump to the top - sorry! (I wish Planets dealt better with small updates so I didn’t have to worry about it).

+

I don’t know what publishing software you use, but I see you provide an Atom feed, and Planet 2.0 and Venus both implement atom:updated as specified in RFC 4287.

+ +
+
+ +

Alf Eaton: Aside: if you’re reading a Planet that contains HubLog, those posts will all jump to the top - sorry! (I wish Planets dealt better with small updates so I didn’t have to worry about it).

+

I don’t know what publishing software you use, but I see you provide an Atom feed, and Planet 2.0 and Venus both implement atom:updated as specified in RFC 4287.

+

More specifically, if you have a minor update and leave the updated date alone, the posts will not jump to the top.  The next release of WordPress, for example, will contain the necessary hooks for a plugin to provide a simple checkbox for indicating that the change constitutes a minor edit.

+ +
+ 2008-09-10T10:18:47-04:00 +
+ + + tag:intertwingly.net,2004:2897 + + + SVG via CSS +
+ +

Now that I have my weblog looking reasonably consistent between Gecko and WebKit based browsers, I’ve taken another look at Opera.  Opera doesn’t have support for border-radius, but does have support for background images in SVG, which can be used to provide the same effect.  My Nav Bar on my test site now employs this technique, and it requires two separate images: 039 on CCD and CCD on FFF.

+

Frankly, my first reaction to this was mixed.  The pluses for SVG in CSS is that it doesn’t require either adjusting your markup or JavaScript to achieve these effects, a desirable characteristic that generally the other techniques don’t share.

+ +
+ +
+ +

Now that I have my weblog looking reasonably consistent between Gecko and WebKit based browsers, I’ve taken another look at Opera.  Opera doesn’t have support for border-radius, but does have support for background images in SVG, which can be used to provide the same effect.  My Nav Bar on my test site now employs this technique, and it requires two separate images: 039 on CCD and CCD on FFF.

+

Meanwhile, Robert O’Callahan has been exploring other ways to integrate these technologies.

+ +
+ 2008-09-07T11:12:29-04:00 +
+ +
+ diff --git a/apps/blagh/rss20.tpl b/apps/blagh/rss20.tpl new file mode 100644 index 0000000..ad9f1db --- /dev/null +++ b/apps/blagh/rss20.tpl @@ -0,0 +1,62 @@ +Content-Type: text/xml; charset=utf-8 + + + +%{ +fn statpost { + f = $1 + + post_uri = `{echo $f | sed 's,^'$sitedir',,'} + title=`{basename $f | sed 's/^[0-9\-]*_(.*)\.md$/\1/; s/_/ /g' } + date=`{/bin/date -Rd `{echo $f|sed 's,.*/([0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9])/.*,\1,'}} + # TODO: use mtime(1) and ls(1) instead of lunix's stat(1) + stat=`{stat -c '%Y %U' $f} + #mdate=`{/bin/date -Rd $stat(1)} # Not used because it is unreliable + post_uri=$base_url^`{cleanname `{echo -n $post_uri | sed 's/\.(md|tpl)//g'}} + by=$stat(2) + ifs=() { + summary=`{awk -v max'='1024 '{ + nc += 1 + length; + if(nc > max) { + print substr($0, 1, nc - max) "..." + exit + } + print + }' $f/index.md |fmt -j| sed 's/\]\]>/Fucking goddamn XML garbage/g'} + } +} + +%} + + + + + %($siteTitle%) + %($req_path%) + %($blogDesc%) + en-us + Tom Duff's rc, and Kris Maglione's clever hackery +%{ + # uriel99+rss@gmail.com (Uriel) + for(f in `{get_post_list $blagh_root$blagh_dirs}) { + statpost $f + # Hack to aproximate the last build date + #(use the mdate from last posted item) + # Commented out for now because maybe a wrong value is worse than no value + #if(~ $#last_build_date 0) { + #last_build_date=''^$"mdate'' + #echo $last_build_date + #} +%} + + %($title%) + %($by%)@noreply.cat-v.org (%($by%)) + %($uri%) + %($uri%) + %($date%) + %($summary%)]]> + +% } + + +