swerc

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

commit 45bcfea95d473db85c48f47da17efe67589b19b5
parent 0189ba99f2bd2e6a5789f43faf2d46b5670848d8
Author: uriel@engel.se.cat-v.org <unknown>
Date:   Mon, 18 Jun 2007 01:45:45 +0200

Add feature to handle shared templates in pub/ and use it for a new sitemap template
Diffstat:
Mbin/controller.rc | 3+++
Apub/sitemap.tpl | 48++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/bin/controller.rc b/bin/controller.rc @@ -93,6 +93,8 @@ fn genbody { cat $body | /bin/sed -i '0,/<body[^>]*>/d;/<\/body>/,$d' if not if ( ~ $body */[bB]log/index */[bB]log//index && ~ $#blogDirs 0 ) blogDirs = `{basename -d $body} + if not if ( test -f pub/^$reqpath^.tpl ) + template.awk pub/^$reqpath^.tpl | rc $rcargs if not if(~ $body */index && ~ $#blogDirs 0) { echo '<h1>' `{basename `{basename -d $body}}'</h1>' echo '<ul>' @@ -146,6 +148,7 @@ template=$sitedir/$template.tpl if (! ~ $#sidebar 0) sidebar=tpl/_inc/$sidebar.tpl +reqpath=$body body=$sitedir/$body rssuri=$uri if (test -d $body) { diff --git a/pub/sitemap.tpl b/pub/sitemap.tpl @@ -0,0 +1,48 @@ +<h1>Site map</h1> + +%{ + +saveddf = $dirfilter +cpath = '' +rpath = `{pwd} +rpath = $rpath^'/'^$sitedir + +fn listDir { + cd $1 + dirfilter = $saveddf + if (test -f _config) + . _config + + echo '<ul>' + for ( i in `{ls -d */ *.md *.html >[2] /dev/null |sed $dirfilter^'/index$/d;' } ) { + cpath = `{ pwd | sed 's,^'^$"rpath/?^',,; s,//*,/,;' } + if( ~ $#cpath 0 ) + cpath = '' + + desc = '' + if (test -f $i.md) { + desc = `{ sed 1q < $i.md } + } + if (test -f $i/index.md) { + desc = `{ sed 1q < $i/index.md } + } + if (test -f $i.html) { + # H1 is not reliable because htmlroff doesn't use it :( + #desc = `{ cat $i.html |sed 32q | grep '<[Hh]1>' |sed 's/<[Hh]1>(.*)(<\/[Hh]1>|$)/\1/;s/<[^>]*>//g;1q' } + # Pick the first line of body instead + desc = `{ cat $i.html |/bin/sed '0,/<[Bb][Oo][Dd][Yy]/d;s/<[^>]*>//g;/^$/d'|sed 1q } + } + if (! ~ $desc '') + desc = ' - '$"desc + tit = `{echo $i|sed 's/_/ /g'} + echo '<li><a style="text-transform: capitalize" href="'$cpath/$i'">'^$"tit^'</a>' $desc '</li>' + if (test -d $i) + listDir $i + } + echo '</ul>' + cd .. +} +cd $sitedir +listDir . + +%}