--- /usr/local/werc/apps/blagh/app.rc	2010-06-11 06:28:39.000000000 +0200
+++ /usr/local/werc/apps/blagh/app.rc	2010-09-06 22:05:42.000000000 +0200
@@ -9,7 +9,7 @@
         conf_blog_editors=blog-editors
 
     if(~ $"conf_max_posts_per_page '')
-        conf_max_posts_per_page=32
+        conf_max_posts_per_page=7
 }
 
 fn blagh_init {
@@ -39,6 +39,10 @@
 '<link rel="alternate" type="application/atom+xml" title="ATOM" href="'$"u'.atom" />
 <link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" />'
         }
+        if not if(~ $req_path $blagh_uri^'sites/'[0-9]*) {
+	    site=`{echo $req_path | sed -e 's/[^0-9]*([0-9]*)$/\1/'}
+            handler_body_main=(blagh_body $site)
+	}
         if not if(~ $req_path $blagh_uri^index.atom)
             blagh_setup_feed_handlers atom.tpl 'application/atom+xml'
 
@@ -72,10 +76,10 @@
 
     # Direct links to feeds are disabled because they are not very useful, add clutter and might waste pagerank.
     # An user can add this on their own using handlers_body_head anyway.
-    #echo '<div style="text-align:right">(<a href="index.rss">RSS Feed</a>|<a href="index.atom">Atom Feed</a>)</div>'
+    echo '<div style="text-align:right">(<a href="index.rss">RSS Feed</a> | <a href="index.atom">Atom Feed</a>)</div>'
 
     { # XXX Not sure why this fixes issues with blog setup, probably bug in fltr_cache!
-    for(p in `{get_post_list $blagh_root^$blagh_dirs}) {
+    for(p in `{get_post_list $blagh_root^$blagh_dirs $1}) {
         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!'}
         sed '1s!.*![&]('^$l(2)^') ('^$l(1)^')!' < $p/index.md 
         echo # Needed extra \n so markdown doesn't mess up the formatting, probably can be done in sed.
@@ -83,12 +87,26 @@
     # 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.
     } | $formatter 
+
+    echo '<div class="navi">'
+    if(expr $1 '>' 0 >/dev/null)
+    	echo '<a href="'^$blagh_uri^'sites/'^`{expr $1 '-' 1}^'" id="skip_forward">&lt;&lt; neuer</a>'
+    echo '<a href="'^$blagh_uri^'sites/'^`{expr $1 '+' 1}^'" id="skip_back">älter &gt;&gt;</a>'
+    echo '</div>'
 }
 
 fn get_post_list {
     # /./->/|/ 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 -e 's,/+\|/+,/,' -e $conf_max_posts_per_page^'q'
+    if(! ~ $2 '' && ! ~ $2 0) {
+	count=`{expr $2 '*' $conf_max_posts_per_page '-' 1}
+        ls -F $1^/./[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,/+\|/+,/,' | /bin/sed -e '1,+'^$count^'d' | sed -e $conf_max_posts_per_page^'q'
+    }
+    if not {
+        ls -F $1^/./[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,/+\|/+,/,' | sed -e $conf_max_posts_per_page^'q'
+    }
 }
 
 fn mkbpost {
--- /usr/local/werc/pub/style/style.css	2010-06-11 06:28:39.000000000 +0200
+++ /usr/local/werc/pub/style/style.css	2010-09-06 21:39:06.000000000 +0200
@@ -328,3 +352,18 @@
 ul.sitemap-list a {
   text-transform: capitalize;
 }
+
+/* Navigation */
+.navi:after {
+	clear: both;
+	color: transparent;
+	content: '.';
+}
+
+a#skip_forward {
+	float: left;
+}
+
+a#skip_back {
+	float: right;
+}

