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 4c56c67284
commit 850e3ec5b9
2 changed files with 33 additions and 25 deletions

View File

@ -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

View File

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