Automatic perm redirect of foo/index to the canonical path foo/, also move the perm redirect function up and delete some unused code
This commit is contained in:
parent
1f66984929
commit
73b8b18679
1 changed files with 20 additions and 15 deletions
|
|
@ -13,18 +13,27 @@ formatter=md_cache # markdown cacher
|
||||||
site=$SERVER_NAME
|
site=$SERVER_NAME
|
||||||
sitedir=sites/$site
|
sitedir=sites/$site
|
||||||
headers=inc/headers.tpl
|
headers=inc/headers.tpl
|
||||||
body=index
|
|
||||||
template=_default
|
template=_default
|
||||||
sidebar=sidebar
|
sidebar=sidebar
|
||||||
baseuri=http://$site/
|
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)
|
for(i in siteTitle siteSubTitle title extraHeaders)
|
||||||
$i = ''
|
$i = ''
|
||||||
|
|
||||||
|
|
||||||
|
# Useful functions
|
||||||
fn dprint {
|
fn dprint {
|
||||||
echo $* >[1=2]
|
echo $* >[1=2]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn perm_redirect {
|
||||||
|
echo 'Status: 301 Moved Permanantly
|
||||||
|
Location: '^$1^'
|
||||||
|
|
||||||
|
'
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Title
|
# Title
|
||||||
fn gentitle {
|
fn gentitle {
|
||||||
echo '<h1 class="headerTitle"><a href="/">' ^ $"siteTitle ^ ' <span id="headerSubTitle">' ^ $"siteSubTitle ^ '</span></a></h1>'
|
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!
|
# Don't change var name or trailing ';', some dirs change the filter!
|
||||||
dirfilter = '/\/[._]/d; s,^\./,,; s,\.md$,,; s,\.html,,; '
|
dirfilter = '/\/[._]/d; s,^\./,,; s,\.md$,,; s,\.html,,; '
|
||||||
|
|
||||||
|
# To be used from _config files
|
||||||
fn hide_paths {
|
fn hide_paths {
|
||||||
for(i in $*) {
|
for(i in $*) {
|
||||||
dirfilter = $dirfilter^'/^'$i'$/d; '
|
dirfilter = $dirfilter^'/^'$i'$/d; '
|
||||||
|
|
@ -199,8 +209,8 @@ fn select_handler {
|
||||||
blogDirs = `{basename -d $body}
|
blogDirs = `{basename -d $body}
|
||||||
|
|
||||||
# Global tpl (eg sitemap.tpl)
|
# Global tpl (eg sitemap.tpl)
|
||||||
if not if (test -f pub/^$reqpath^.tpl)
|
if not if (test -f pub/^$body^.tpl)
|
||||||
set_handler tpl_handler pub/^$reqpath^.tpl
|
set_handler tpl_handler pub/^$body^.tpl
|
||||||
|
|
||||||
if not if (test -f $body.txt)
|
if not if (test -f $body.txt)
|
||||||
set_handler txt_handler $body.txt
|
set_handler txt_handler $body.txt
|
||||||
|
|
@ -232,13 +242,18 @@ fn genbody {
|
||||||
if(! ~ $#debug 0)
|
if(! ~ $#debug 0)
|
||||||
dprint ' ' $SERVER_NAME^$REQUEST_URI^' - '^$"HTTP_USER_AGENT
|
dprint ' ' $SERVER_NAME^$REQUEST_URI^' - '^$"HTTP_USER_AGENT
|
||||||
|
|
||||||
|
|
||||||
if (! ~ $args '') {
|
if (! ~ $args '') {
|
||||||
|
if (~ $args($#args) 'index')
|
||||||
|
perm_redirect `{ echo $REQUEST_URI | sed 's,/index$,/,' }
|
||||||
|
|
||||||
#title=$args($#args)
|
#title=$args($#args)
|
||||||
title=$args
|
title=$args
|
||||||
title=`{echo $title | sed -e 's/ / - /g' -e 's/_/ /g' }
|
title=`{echo $title | sed -e 's/ / - /g' -e 's/_/ /g' }
|
||||||
body=$uri
|
body=$uri
|
||||||
}
|
}
|
||||||
|
if not {
|
||||||
|
body='/'
|
||||||
|
}
|
||||||
|
|
||||||
fpath=$sitedir
|
fpath=$sitedir
|
||||||
for (i in ('' $args)) {
|
for (i in ('' $args)) {
|
||||||
|
|
@ -256,14 +271,6 @@ for (i in ('' $args)) {
|
||||||
inBlog = 'yes'
|
inBlog = 'yes'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn perm_redirect {
|
|
||||||
echo 'Status: 301 Moved Permanantly
|
|
||||||
Location: '^$1^'
|
|
||||||
|
|
||||||
'
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
|
|
||||||
# Redirections and other preprocessing
|
# Redirections and other preprocessing
|
||||||
if (~ $#redirectPermanent 1)
|
if (~ $#redirectPermanent 1)
|
||||||
perm_redirect $"redirectPermanent
|
perm_redirect $"redirectPermanent
|
||||||
|
|
@ -285,8 +292,6 @@ if (! ~ $#sidebar 0)
|
||||||
body=$sitedir/$body
|
body=$sitedir/$body
|
||||||
rssuri=$uri
|
rssuri=$uri
|
||||||
|
|
||||||
#if(~ $body */index)
|
|
||||||
#perm_redirect `{ echo $REQUEST_URI | sed 's,/index$,/,' }
|
|
||||||
|
|
||||||
if (test -d $body) {
|
if (test -d $body) {
|
||||||
if(! ~ $body */)
|
if(! ~ $body */)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue