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.
This commit is contained in:
Uriel 2008-12-20 13:20:31 +01:00
parent 11ead1335c
commit f1f653f876
2 changed files with 33 additions and 25 deletions

View file

@ -3,7 +3,7 @@
%{ %{
tmpfile=/tmp/werc_sitemap_$pid.txt tmpfile=/tmp/werc_sitemap_$pid.txt
echo '' > $tmpfile echo '' > $tmpfile
saveddf = $dirfilter saveddf=$dirfilter
fn getMdDesc { fn getMdDesc {
sed 's/^(.......................................................................................................[^ ]*).*$/\1/g; 1q' < $1 sed 's/^(.......................................................................................................[^ ]*).*$/\1/g; 1q' < $1
@ -11,51 +11,56 @@ fn getMdDesc {
fn listDir { fn listDir {
d=$1 d=$1
dirfilter = $saveddf if(~ $#d 0)
blogDirs = () d=''
if (test -f $d/_werc/config) dirfilter=$saveddf
. $d/_werc/config blogDirs=()
if(test -f $d/_werc/config)
. ./$d/_werc/config
echo '<ul>' echo '<ul class="sitemap-list">'
# Don't hide blog dirs for now # Don't hide blog dirs for now
#if (! ~ $#blogDirs 0 || ~ $1 */blog */Blog ) #if(! ~ $#blogDirs 0 || ~ $1 */blog */Blog)
# echo '' # echo ''
#if not #if not
if(! ~ $#redirectPermanent 1) if(! ~ $#redirectPermanent 1)
{ {
for ( i in `{ ls -d $d/*/ $d/*.md $d/*.html $d/*.txt >[2]/dev/null |sed $dirfilter} ) { for(i in `{ls -dF $d^*/ $d^*.md $d^*.html $d^*.txt >[2]/dev/null | sed $dirfilter}) {
desc = '' desc=''
if (test -f $i.md) { if(test -f $i.md)
desc = `{ getMdDesc $i.md } desc=`{getMdDesc $i.md}
} if not if(~ $i */ && test -f $i/index.md)
if (test -f $i/index.md) { desc=`{getMdDesc $i/index.md}
desc = `{ getMdDesc $i/index.md } if not if(test -f $i.html) {
}
if (test -f $i.html) {
# H1 is not reliable because htmlroff doesn't use it :( # 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 # 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 if(! ~ $#desc 0 && ! ~ $desc '')
tit = `{basename $i|sed 's/_/ /g'} desc=' - '$"desc
echo '<li><a style="text-transform: capitalize" href="/'$i'">'^$"tit^'</a>' $desc '</li>' tit=`{echo /$i|sed 's/_/ /g; s,.*/([^/]+)/?$,\1,'}
echo '<li><a href="/'$i'">'^$"tit^'</a>' $"desc '</li>'
echo -n $baseuri^$i >> $tmpfile echo -n $baseuri^$i >> $tmpfile
if (test -d $i) { if(test -d $i) {
echo / >> $tmpfile echo / >> $tmpfile
@{ listDir $i } @{ listDir $i }
} }
if not echo >> $tmpfile if not
echo >> $tmpfile
} }
} }
echo '</ul>' echo '</ul>'
} }
cd $sitedir cd $sitedir
listDir . listDir ''
cp $tmpfile ./sitemap.txt cp $tmpfile ./sitemap.txt
rm $tmpfile rm $tmpfile

View file

@ -369,3 +369,6 @@ h1.dir-list-head, ul.dir-list {
text-transform: capitalize; text-transform: capitalize;
font-weight: bold; font-weight: bold;
} }
ul.sitemap-list a {
text-transform: capitalize;
}