shithub: werc

Download patch

ref: 51ad1dad502c4dee7e26d98d3c3aafe2fcb05f1b
parent: f4387dc88847623cc85490eb37fe715ccc10552f
author: uriel <uriel@engel.se.cat-v.org>
date: Thu Aug 28 19:32:07 EDT 2008

Automatic perm redirect of foo/index to the canonical path foo/, also move the perm redirect function up and delete some unused code

--- a/bin/controller.rc
+++ b/bin/controller.rc
@@ -13,18 +13,27 @@
 site=$SERVER_NAME
 sitedir=sites/$site
 headers=inc/headers.tpl
-body=index
 template=_default
 sidebar=sidebar
 baseuri=http://$site/
-reqpath=$body # Maybe this is not needed anymore now that the handlers are selected before anybody can mess with $body
 for(i in siteTitle siteSubTitle title extraHeaders)
     $i = ''
 
+
+# Useful functions
 fn dprint {
     echo $* >[1=2]
 }
 
+fn perm_redirect {
+    echo 'Status: 301 Moved Permanantly
+Location: '^$1^'
+
+'
+    exit
+}
+
+
 # Title
 fn gentitle {
     echo '<h1 class="headerTitle"><a href="/">' ^ $"siteTitle ^ ' <span id="headerSubTitle">' ^ $"siteSubTitle ^ '</span></a></h1>'
@@ -33,6 +42,7 @@
 # Don't change var name or trailing ';', some dirs change the filter!
 dirfilter = '/\/[._]/d; s,^\./,,; s,\.md$,,; s,\.html,,; '
 
+# To be used from _config files
 fn hide_paths {
     for(i in $*) {
 	dirfilter = $dirfilter^'/^'$i'$/d; '
@@ -199,8 +209,8 @@
         blogDirs = `{basename -d $body}
 
     # Global tpl (eg sitemap.tpl)
-    if not if (test -f pub/^$reqpath^.tpl)
-        set_handler tpl_handler pub/^$reqpath^.tpl
+    if not if (test -f pub/^$body^.tpl)
+        set_handler tpl_handler pub/^$body^.tpl
 
     if not if (test -f $body.txt)
         set_handler txt_handler $body.txt
@@ -232,13 +242,18 @@
 if(! ~ $#debug 0)
     dprint '  ' $SERVER_NAME^$REQUEST_URI^' - '^$"HTTP_USER_AGENT
 
-
 if (! ~ $args '') {
+    if (~ $args($#args) 'index')
+        perm_redirect `{ echo $REQUEST_URI | sed 's,/index$,/,' }
+        
     #title=$args($#args)
     title=$args
     title=`{echo $title | sed -e 's/ / - /g' -e 's/_/ /g' }
     body=$uri
 }
+if not {
+    body='/'
+}
 
 fpath=$sitedir
 for (i in ('' $args)) {
@@ -256,14 +271,6 @@
         inBlog = 'yes'
 }
 
-fn perm_redirect {
-    echo 'Status: 301 Moved Permanantly
-Location: '^$1^'
-
-'
-    exit
-}
-
 # Redirections and other preprocessing
 if (~ $#redirectPermanent 1)
     perm_redirect $"redirectPermanent
@@ -285,8 +292,6 @@
 body=$sitedir/$body
 rssuri=$uri
 
-#if(~ $body */index)
-    #perm_redirect `{ echo $REQUEST_URI | sed 's,/index$,/,' }
 
 if (test -d $body) {
     if(! ~ $body */)