changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > werc / changeset: Move blagh feed templates to app dir, be smarter when enabling 'implicit' blogs, and upgrade the web interface for blog posting.

changeset 363: ff4820ab2336
parent 362: dbb8039cd374
child 364: 348ed2987106
author: uriel@engel.se.cat-v.org
date: Sun, 25 Jan 2009 16:52:19 +0100
files: apps/blagh/app.rc apps/blagh/atom.tpl apps/blagh/rss20.tpl
description: Move blagh feed templates to app dir, be smarter when enabling 'implicit' blogs, and upgrade the web interface for blog posting.
     1.1--- a/apps/blagh/app.rc	Sun Jan 25 16:42:22 2009 +0100
     1.2+++ b/apps/blagh/app.rc	Sun Jan 25 16:52:19 2009 +0100
     1.3@@ -6,8 +6,8 @@
     1.4 }
     1.5 
     1.6 fn blagh_init {
     1.7-    if(~ $#blagh_dirs 0 && ~ $req_path */[bB]log/) {
     1.8-        blagh_uri=$req_path
     1.9+    if(~ $#blagh_dirs 0 && ~ $req_path */[bB]log/*) {
    1.10+        blagh_uri=`{echo $req_path | sed 's,(/[bB]log/).*,\1,'}
    1.11         blagh_dirs=( . )
    1.12     }
    1.13 
    1.14@@ -16,26 +16,40 @@
    1.15     # && test -d / `{echo '-a -d '^$blagh_root^$blagh_dirs}
    1.16         blagh_url=$base_url^$blagh_uri
    1.17         blagh_root=$sitedir^$blagh_uri
    1.18+        if(check_user $blog_editors admin) {
    1.19+            editor_mode=on
    1.20+            ll_add handlers_bar_left echo '<a href="'$blagh_uri'new_post">Make a new post</a>'
    1.21+        }
    1.22 
    1.23-        if(~ $req_path */ && ~ $req_path $blagh_uri) {
    1.24+        switch($req_path) {
    1.25+        case $blagh_uri
    1.26             handler_body_main=blagh_body
    1.27             u=$blagh_uri'index'
    1.28             extraHeaders=$"extraHeaders ^ \
    1.29-            '<link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" />
    1.30+'<link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" />
    1.31 <link rel="alternate" type="application/atom+xml" title="ATOM" href="'$"u'.atom" />'
    1.32-
    1.33+        case $blagh_uri^index.atom
    1.34+            blagh_setup_feed_handlers atom.tpl
    1.35+        case $blagh_uri^index.rss
    1.36+            blagh_setup_feed_handlers rss20.tpl
    1.37+        case $blagh_uri^new_post 
    1.38+            if(! ~ $#editor_mode 0) {
    1.39+                if(~ $REQUEST_METHOD GET)
    1.40+                    handler_body_main=( tpl_handler `{get_lib_file blagh/new_post.tpl apps/blagh/new_post.tpl} )
    1.41+                if not if(~ $REQUEST_METHOD POST) {
    1.42+                    mkbpost $post_arg_id $post_arg_title $post_arg_body
    1.43+                    post_redirect $blagh_uri
    1.44+                }
    1.45+            }
    1.46         }
    1.47-        if not if(~ $req_path */index.atom)
    1.48-            blagh_setup_feed_handlers atom.tpl
    1.49-        if not if(~ $req_path */index.rss)
    1.50-            blagh_setup_feed_handlers rss20.tpl
    1.51+        
    1.52     }
    1.53 }
    1.54 
    1.55 fn blagh_setup_feed_handlers {
    1.56     handler_body_main=NOT_USED_by_blagh_feeds
    1.57     res_tail=()
    1.58-    master_template=_apps/blagh/$1
    1.59+    master_template=apps/blagh/$1 # Should we allow tempalte override?
    1.60 }
    1.61 
    1.62 fn blagh_body {
    1.63@@ -46,30 +60,35 @@
    1.64 }
    1.65 
    1.66 fn get_post_list {
    1.67-    # the /./->/|/ are added so we can sort -t| and order only the file name
    1.68-    # NOTE: this breaks if any path element in blagh_dirs contain '/./' or '|'
    1.69+    # /./->/|/ done to sort -t| and order by date
    1.70+    # Note: $paths in blagh_dirs should not contain '/./' or '|'
    1.71     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,/+\|/+,/,'
    1.72 }
    1.73 
    1.74-
    1.75-fn make_blog_post {
    1.76-    if(! ~ 0 $#1 $#2 $#3) {
    1.77-        bdir=$1
    1.78-        btitle=$2
    1.79-        btext=$3
    1.80-        date=`{/bin/date +%F}
    1.81-
    1.82-        n=1
    1.83-        for(f in $bdir^$date^'-'*) {
    1.84-            i=`{echo -n $f | sed -n 's,^.*/'$date'-([0-9]+)_.*,\1,p'|tr -d $NEW_LINE}
    1.85-            if(! ~ $#i 0 && test $i -ge $n)
    1.86-                n=`{hoc -e $i'+1'}
    1.87-        }
    1.88-        btitle=`{echo -n $"btitle | sed 's/[ 	]+/_/g; 1q'}
    1.89-
    1.90-        echo $btext > $bdir^'/'^$"date^'-'^$"n^_$"btitle.md 
    1.91+fn mkbpost {
    1.92+    if(! ~ 0 $#1 $#2) {
    1.93+        umask 002 # Let group write
    1.94+        bptitle=$1
    1.95+        bptext=$2
    1.96+        if(! ~ $#3 0)
    1.97+            bpid=`{echo -n '-'^$"bpid | sed 's/'$forbidden_uri_chars'+/_/g; 1q'}
    1.98+        d=`{/bin/date +%F|sed 's,-,/,g'}
    1.99+        
   1.100+        ddir=$blagh_root^$d^'/'
   1.101+        n=`{ls $ddir >[2]/dev/null |wc -l}
   1.102+        
   1.103+        mkdir -p $ddir/$"n^$"bpid/
   1.104+        {
   1.105+            echo $bptitle
   1.106+            echo '========================================='
   1.107+            # TODO: Enable metadata
   1.108+            #echo '* Posted:' `{date}
   1.109+            #if(! ~ $#logged_user 0)
   1.110+            #   echo '* Author: '$logged_user
   1.111+            echo 
   1.112+            echo $bptext
   1.113+        }> $ddir/$"n^$"bpid/index.md 
   1.114     }
   1.115     if not
   1.116-        status=Missing blog post arguments $"1 $"2 $"3 
   1.117+        status=Missing blog post arguments $"1 $"2
   1.118 }
   1.119-
     2.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2+++ b/apps/blagh/atom.tpl	Sun Jan 25 16:52:19 2009 +0100
     2.3@@ -0,0 +1,140 @@
     2.4+Content-Type: application/atom+xml
     2.5+
     2.6+<?xml version="1.0" encoding="utf-8"?>
     2.7+
     2.8+<!-- TODO: See for more info:http://www.tbray.org/ongoing/When/200x/2005/07/27/Atomic-RSS  -->
     2.9+%{
    2.10+fn statpost {
    2.11+    f = $1
    2.12+
    2.13+    updated = `{/bin/date --rfc-3339'=seconds' -r $f |tr ' ' 'T'} 
    2.14+    post_uri=$base_url^`{cleanname `{echo $f | sed -e 's!^'$sitedir'!!' -e 's/\.(md|tpl)$//g'}}
    2.15+    title=`{read $f/index.md}
    2.16+    # Not used: date=`{/bin/date -Rd `{basename $f |sed 's/(^[0-9\-]*).*/\1/; s/-[0-9]$//'}}
    2.17+    # TODO: use mtime(1) and ls(1) instead of lunix's stat(1)
    2.18+    stat=`{stat -c '%Y %U' $f}
    2.19+    #mdate=`{/bin/date -Rd `{mtime $f|awk '{print $1}' }} # Not used because it is unreliable
    2.20+    by=$stat(2)
    2.21+    ifs=() { summary=`{cat $f/index.md | crop_text 512 ... | $formatter } }
    2.22+}
    2.23+updated = `{/bin/date --rfc-3339'=seconds' |sed 's/ /T/'} 
    2.24+%}
    2.25+
    2.26+<feed xmlns="http://www.w3.org/2005/Atom"
    2.27+    xmlns:thr="http://purl.org/syndication/thread/1.0">
    2.28+
    2.29+    <link rel="self" href="%($req_path%)"/>
    2.30+    <id>%($req_path%)</id>
    2.31+    <icon>/favicon.ico</icon>
    2.32+
    2.33+    <title>%($siteTitle%)</title>
    2.34+    <subtitle>%($siteSubTitle%)</subtitle>
    2.35+
    2.36+    <!-- <updated>2008-09-24T12:47:00-04:00</updated> -->
    2.37+    <updated>%($updated%)</updated>
    2.38+    <link href="."/>
    2.39+
    2.40+%{
    2.41+        for(f in `{get_post_list $blagh_root$blagh_dirs}) {
    2.42+            statpost $f
    2.43+%}
    2.44+    <entry>
    2.45+        <!-- Maybe we should be smarter, see: http://diveintomark.org/archives/2004/05/28/howto-atom-id, example: <id>tag:intertwingly.net,2004:2899</id>  -->
    2.46+        <id>%($post_uri%)</id>
    2.47+        <link href="%($post_uri%)"/>
    2.48+        <title>%($title%)</title>
    2.49+        <!-- <link rel="replies" href="2899.atom" thr:count="0"/> -->
    2.50+        <author>
    2.51+            <name>%($by%)</name>
    2.52+        </author>
    2.53+
    2.54+
    2.55+        <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
    2.56+            %($summary%)
    2.57+        </div></content>
    2.58+
    2.59+        <updated>%($updated%)</updated>
    2.60+    </entry>
    2.61+
    2.62+
    2.63+%        }
    2.64+
    2.65+</feed>
    2.66+
    2.67+% exit 
    2.68+
    2.69+<feed xmlns="http://www.w3.org/2005/Atom"
    2.70+  xmlns:thr="http://purl.org/syndication/thread/1.0">
    2.71+  <link rel="self" href="http://intertwingly.net/blog/index.atom"/>
    2.72+  <id>http://intertwingly.net/blog/index.atom</id>
    2.73+  <icon>../favicon.ico</icon>
    2.74+
    2.75+  <title>Sam Ruby</title>
    2.76+  <subtitle>It’s just data</subtitle>
    2.77+  <author>
    2.78+    <name>Sam Ruby</name>
    2.79+    <email>rubys@intertwingly.net</email>
    2.80+    <uri>/blog/</uri>
    2.81+  </author>
    2.82+  <updated>2008-09-24T12:47:00-04:00</updated>
    2.83+  <link href="/blog/"/>
    2.84+  <link rel="license" href="http://creativecommons.org/licenses/BSD/"/>
    2.85+
    2.86+  <entry>
    2.87+    <id>tag:intertwingly.net,2004:2899</id>
    2.88+    <link href="/blog/2008/09/11/RubyConf-2008"/>
    2.89+    <link rel="replies" href="2899.atom" thr:count="0"/>
    2.90+    <title>RubyConf 2008</title>
    2.91+    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
    2.92+    
    2.93+<p>My <a href="http://www.rubyconf.org/talks/14">proposal</a> has been accepted for <a href="http://www.rubyconf.org/talks">RubyConf 2008</a>.  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 <a href="http://intertwingly.net/blog/2008/07/24/Ruby-1-9-What-to-Expect">OSCON</a>, that there will be members of the audience who know way more about this subject than I do.</p>
    2.94+<p>I had originally requested a slot on Saturday.  My current slot requires me to shave a day off of <a href="http://us.apachecon.com/c/acus2008/">ApacheCon</a>.  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.</p>
    2.95+
    2.96+    </div></content>
    2.97+    <updated>2008-09-11T06:51:36-04:00</updated>
    2.98+  </entry>
    2.99+
   2.100+  <entry>
   2.101+    <id>tag:intertwingly.net,2004:2898</id>
   2.102+    <link href="/blog/2008/09/10/Small-Updates"/>
   2.103+    <link rel="replies" href="2898.atom" thr:count="8" thr:updated="2008-09-10T15:31:05-04:00"/>
   2.104+    <title>Small Updates</title>
   2.105+    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
   2.106+    
   2.107+    <p><a href="http://hublog.hubmed.org/archives/001744.html">Alf Eaton</a>: <em>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).</em></p>
   2.108+<p>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 <a href="http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.updated">atom:updated</a> as specified in RFC 4287.</p>
   2.109+
   2.110+    </div></summary>
   2.111+    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
   2.112+
   2.113+<p><a href="http://hublog.hubmed.org/archives/001744.html"><cite>Alf Eaton</cite></a>: <em>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).</em></p>
   2.114+<p>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 <a href="http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.updated">atom:updated</a> as specified in RFC 4287.</p>
   2.115+<p>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 <a href="http://blog.ciarang.com/posts/wp-minor-edit/">plugin</a> to provide a simple checkbox for indicating that the change constitutes a minor edit.</p>
   2.116+
   2.117+    </div></content>
   2.118+    <updated>2008-09-10T10:18:47-04:00</updated>
   2.119+  </entry>
   2.120+
   2.121+  <entry>
   2.122+    <id>tag:intertwingly.net,2004:2897</id>
   2.123+    <link href="/blog/2008/09/07/SVG-via-CSS"/>
   2.124+    <link rel="replies" href="2897.atom" thr:count="10" thr:updated="2008-09-12T02:21:21-04:00"/>
   2.125+    <title>SVG via CSS</title>
   2.126+    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
   2.127+    
   2.128+    <p>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 <a href="http://dev.opera.com/articles/view/new-development-techniques-using-opera-k/">used to provide the same effect</a>.  My Nav Bar on <a href="http://rails.intertwingly.net/blog/">my test site</a> now employs this technique, and it requires two separate images: <a href="http://rails.intertwingly.net/stylesheets/rc-039-CCD.svg">039 on CCD</a> and <a href="http://rails.intertwingly.net/stylesheets/rc-CCD-FFF.svg">CCD on FFF</a>.</p>
   2.129+<p>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 <a href="http://www.cssjuice.com/25-rounded-corners-techniques-with-css/">other techniques</a> don’t share.</p>
   2.130+
   2.131+    </div></summary>
   2.132+
   2.133+    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
   2.134+    
   2.135+<p>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 <a href="http://dev.opera.com/articles/view/new-development-techniques-using-opera-k/">used to provide the same effect</a>.  My Nav Bar on <a href="http://rails.intertwingly.net/blog/">my test site</a> now employs this technique, and it requires two separate images: <a href="http://rails.intertwingly.net/stylesheets/rc-039-CCD.svg">039 on CCD</a> and <a href="http://rails.intertwingly.net/stylesheets/rc-CCD-FFF.svg">CCD on FFF</a>.</p>
   2.136+<p>Meanwhile, Robert O’Callahan has been exploring <a href="http://weblogs.mozillazine.org/roc/archives/2008/06/applying_svg_ef.html">other ways</a> to integrate these technologies.</p>
   2.137+
   2.138+    </div></content>
   2.139+    <updated>2008-09-07T11:12:29-04:00</updated>
   2.140+  </entry>
   2.141+
   2.142+</feed>
   2.143+
     3.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2+++ b/apps/blagh/rss20.tpl	Sun Jan 25 16:52:19 2009 +0100
     3.3@@ -0,0 +1,62 @@
     3.4+Content-Type: text/xml; charset=utf-8
     3.5+
     3.6+<?xml version="1.0" encoding="UTF-8"?>
     3.7+
     3.8+%{
     3.9+fn statpost {
    3.10+	f = $1
    3.11+
    3.12+	post_uri = `{echo $f | sed 's,^'$sitedir',,'}
    3.13+	title=`{basename $f | sed 's/^[0-9\-]*_(.*)\.md$/\1/; s/_/ /g' }
    3.14+	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,'}}
    3.15+	# TODO: use mtime(1) and ls(1) instead of lunix's stat(1)
    3.16+	stat=`{stat -c '%Y %U' $f}
    3.17+	#mdate=`{/bin/date -Rd $stat(1)} # Not used because it is unreliable
    3.18+	post_uri=$base_url^`{cleanname `{echo -n $post_uri | sed 's/\.(md|tpl)//g'}}
    3.19+	by=$stat(2)
    3.20+	ifs=() {
    3.21+		summary=`{awk -v max'='1024 '{
    3.22+			nc += 1 + length;
    3.23+			if(nc > max) {
    3.24+				print substr($0, 1, nc - max) "..."
    3.25+				exit
    3.26+			}
    3.27+			print
    3.28+		}' $f/index.md |fmt -j| sed 's/\]\]>/Fucking goddamn XML garbage/g'}
    3.29+	}
    3.30+}
    3.31+
    3.32+%}
    3.33+
    3.34+<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    3.35+	<channel>
    3.36+		<atom:link href="%('http://'$site^$req_path%)" rel="self" type="application/rss+xml" />
    3.37+		<title>%($siteTitle%)</title>
    3.38+		<link>%($req_path%)</link>
    3.39+		<description>%($blogDesc%)</description>
    3.40+		<language>en-us</language>
    3.41+		<generator>Tom Duff's rc, and Kris Maglione's clever hackery</generator>
    3.42+%{
    3.43+		# <webMaster>uriel99+rss@gmail.com (Uriel)</webMaster>
    3.44+        for(f in `{get_post_list $blagh_root$blagh_dirs}) {
    3.45+			statpost $f
    3.46+			# Hack to aproximate the last build date 
    3.47+			#(use the mdate from last posted item)
    3.48+			# Commented out for now because maybe a wrong value is worse than no value
    3.49+			#if(~ $#last_build_date 0) {
    3.50+				#last_build_date='<lastBuildDate>'^$"mdate'</lastBuildDate>'
    3.51+				#echo $last_build_date
    3.52+			#}
    3.53+%}
    3.54+		<item>
    3.55+			<title>%($title%)</title>
    3.56+			<author>%($by%)@noreply.cat-v.org (%($by%))</author>
    3.57+			<link>%($uri%)</link>
    3.58+                        <guid isPermaLink="true">%($uri%)</guid>
    3.59+			<pubDate>%($date%)</pubDate>
    3.60+			<description><![CDATA[<pre>%($summary%)</pre>]]></description>
    3.61+		</item>
    3.62+%		}
    3.63+
    3.64+	</channel>
    3.65+</rss>