swerc

anselm's simpler werc fork
git clone git://git.suckless.org/swerc
Log | Files | Refs | README

commit ec752f625638956d9a6daffaac6b07e2785f2596
parent 2ec590ca7cc00a5706bb9581d59c7e0d2615b280
Author: uriel@engel.se.cat-v.org <unknown>
Date:   Thu, 28 Aug 2008 23:32:07 +0200

Automatic perm redirect of foo/index to the canonical path foo/, also move the perm redirect function up and delete some unused code
Diffstat:
Mbin/controller.rc | 35++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/bin/controller.rc b/bin/controller.rc @@ -13,18 +13,27 @@ formatter=md_cache # markdown cacher 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 @@ fn gentitle { # 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 @@ fn select_handler { 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 @@ fn genbody { 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 @@ for (i in ('' $args)) { 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 @@ if (! ~ $#sidebar 0) body=$sitedir/$body rssuri=$uri -#if(~ $body */index) - #perm_redirect `{ echo $REQUEST_URI | sed 's,/index$,/,' } if (test -d $body) { if(! ~ $body */)