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

@ -90,6 +90,36 @@ fn get_md_file_attr {
sed -n '/^\* '$2': /p; /^\* '$2': /q; /^$/q' < $1
}
# File title extraction
fn get_md_title {
#sed 's/^(................................................................[^ ]*).*$/\1/g; 1q' < $1
sed -n -e '1N; /^.*\n===*$/N; /.*\n===*\n$/!b' -e 's/\n==*\n//p' < $1
}
fn get_html_title {
# H1 is not reliable because htmlroff doesn't use it :(
#desc=`{cat $1 | sed 32q | grep '<[Hh]1>' | sed 's/<[Hh]1>(.*)(<\/[Hh]1>|$)/\1/;s/<[^>]*>//g;1q'}
# Pick the first line of body instead
desc=`{sed -n '/<[Bb][Oo][Dd][Yy]/,/./s/(<[^>]*>|$)//gp' < $1}
if(~ $#desc 0)
desc=`{sed 's/<[^>]*>//g; 1q' < $1}
}
fn get_file_title {
if (~ $1 *.md)
get_md_title $1
if not if(~ $1 *.html)
get_html_title $1
if not if(~ $1 */) {
if(test -f $1/index.md)
get_md_title $1/index.md
if not if(test -f $1/index.html)
get_html_title $1/index.html
}
}
##########################################################################
##########################################################################
#app_blog_methods = ( _post index.rss )