commit 6e9bf1d52439f1d46da6c4554d6dddafac97ada9
parent 73a136f87f8bbf39106c635ee34f1689b61d3b5d
Author: uriel@engel.se.cat-v.org <unknown>
Date: Sat, 20 Dec 2008 13:20:31 +0100
Sitemap improvemnts and cleanups:
- Avoid nedless tests
- Replace reference to /bin/sed with faster, simpler and probably more correct plan9 sed call.
- Move inline html styling to style.css
- Various code cleanups, bring source style in line with other werc source.
Diffstat:
2 files changed, 33 insertions(+), 25 deletions(-)
diff --git a/lib/sitemap.tpl b/lib/sitemap.tpl
@@ -3,7 +3,7 @@
%{
tmpfile=/tmp/werc_sitemap_$pid.txt
echo '' > $tmpfile
-saveddf = $dirfilter
+saveddf=$dirfilter
fn getMdDesc {
sed 's/^(.......................................................................................................[^ ]*).*$/\1/g; 1q' < $1
@@ -11,51 +11,56 @@ fn getMdDesc {
fn listDir {
d=$1
- dirfilter = $saveddf
- blogDirs = ()
- if (test -f $d/_werc/config)
- . $d/_werc/config
+ if(~ $#d 0)
+ d=''
+ dirfilter=$saveddf
+ blogDirs=()
+ if(test -f $d/_werc/config)
+ . ./$d/_werc/config
- echo '<ul>'
+ echo '<ul class="sitemap-list">'
# Don't hide blog dirs for now
- #if (! ~ $#blogDirs 0 || ~ $1 */blog */Blog )
+ #if(! ~ $#blogDirs 0 || ~ $1 */blog */Blog)
# echo ''
#if not
if(! ~ $#redirectPermanent 1)
{
- for ( i in `{ ls -d $d/*/ $d/*.md $d/*.html $d/*.txt >[2]/dev/null |sed $dirfilter} ) {
- desc = ''
- if (test -f $i.md) {
- desc = `{ getMdDesc $i.md }
- }
- if (test -f $i/index.md) {
- desc = `{ getMdDesc $i/index.md }
- }
- if (test -f $i.html) {
+ for(i in `{ls -dF $d^*/ $d^*.md $d^*.html $d^*.txt >[2]/dev/null | sed $dirfilter}) {
+ desc=''
+ if(test -f $i.md)
+ desc=`{getMdDesc $i.md}
+ if not if(~ $i */ && test -f $i/index.md)
+ desc=`{getMdDesc $i/index.md}
+ if not 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' }
+ #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 = `{ /bin/sed -e '0,/<[Bb][Oo][Dd][Yy]/d;s/<[^>]*>//g;/^$/d' < $i.html >[2]/dev/null | sed 1q }
+ desc=`{sed -n '/<[Bb][Oo][Dd][Yy]/,/./s/(<[^>]*>|$)//gp' < $i.html}
+ if(~ $#desc 0)
+ desc=`{sed 's/<[^>]*>//g; 1q' < $i.html}
+ #desc=`{/bin/sed -e '0,/<[Bb][Oo][Dd][Yy]/d;s/<[^>]*>//g;/^$/d' < $i.html >[2]/dev/null | sed 1q}
}
- if (! ~ $desc '')
- desc = ' - '$"desc
- tit = `{basename $i|sed 's/_/ /g'}
- echo '<li><a style="text-transform: capitalize" href="/'$i'">'^$"tit^'</a>' $desc '</li>'
+
+ if(! ~ $#desc 0 && ! ~ $desc '')
+ desc=' - '$"desc
+ tit=`{echo /$i|sed 's/_/ /g; s,.*/([^/]+)/?$,\1,'}
+ echo '<li><a href="/'$i'">'^$"tit^'</a>' $"desc '</li>'
echo -n $baseuri^$i >> $tmpfile
- if (test -d $i) {
+ if(test -d $i) {
echo / >> $tmpfile
@{ listDir $i }
}
- if not echo >> $tmpfile
+ if not
+ echo >> $tmpfile
}
}
echo '</ul>'
}
cd $sitedir
-listDir .
+listDir ''
cp $tmpfile ./sitemap.txt
rm $tmpfile
diff --git a/pub/style/style.css b/pub/style/style.css
@@ -369,3 +369,6 @@ h1.dir-list-head, ul.dir-list {
text-transform: capitalize;
font-weight: bold;
}
+ul.sitemap-list a {
+ text-transform: capitalize;
+}