New context var 'local_file' that will point to the on-disk-file that represents the main content of a given page request (if such exists, otherwise it is '' or ()).

Move title extracting functions from sitemap.tpl to werclib.rc.
Rewrite .md title extraction code to only match first lines when 'underlines' with =.

Use the changes above to generate better page titles when possible.
This commit is contained in:
Uriel 2009-07-28 20:28:35 +02:00
parent a2e426eb11
commit 2d8ce10389
4 changed files with 61 additions and 40 deletions

View file

@ -46,6 +46,7 @@ fn werc_exec_request {
req_path=`{echo -n $REQUEST_URI | sed 's/\?.*//; s!//+!/!g; s/%5[Ff]/_/g; s/'^$forbidden_uri_chars^'//g; s/\.\.*/./g; 1q'}
req_url=$base_url^$req_path
local_path=$sitedir$req_path
local_file=''
ifs='/' { args=`{echo -n $req_path} }
# Preload post args for templates where cgi's stdin is not accessible
@ -103,14 +104,24 @@ fn werc_exec_request {
perm_redirect $t
}
setup_handlers
# Set Page title
if(~ $"pageTitle '')
if(! ~ $local_file '') {
t=`{get_file_title $local_file}
if(! ~ $"t '')
pageTitle=$t
}
dprint X^$"pageTitle^X
# XXX Is this never true? because we set pageTitle earlier based on url.
if(~ $"pageTitle '')
pageTitle=$"siteTitle' '$"siteSubTitle
if not
pageTitle=$"pageTitle' | '$"siteTitle' '$"siteSubTitle
setup_handlers
for(h in $extraHttpHeaders)
echo $h
echo 'Content-Type: '^$http_content_type