sitemap.tpl (1751B)
1 <h1>Site map</h1> 2 3 %{ 4 tmpfile=/tmp/werc_sitemap_$pid.txt 5 tmpfilex=/tmp/werc_sitemapx_$pid.txt 6 saveddf=$dirfilter 7 8 MON2NUM='s/Jan/01/; s/Feb/02/; s/Mar/03/; s/Apr/04/; s/May/05/; s/Jun/06/; s/Jul/07/; s/Aug/08/; s/Sep/09/; s/Oct/10/; s/Nov/11/; s/Dec/12/;' 9 10 fn get_mdate { 11 t=`{mtime $1} 12 t=`{date $t(1) | sed -e $MON2NUM -e 's/ ([0-9]) / 0\1 /g'} # Make sure day of the month is two digits. 13 echo $t(6)^'-'^$t(2)^'-'^$t(3) 14 } 15 16 fn listDir { 17 d=$1 18 dirfilter=$saveddf 19 if(test -f $d/_werc/config) 20 . $d/_werc/config 21 22 if(~ $#perm_redir_to 0) { 23 echo '<ul class="sitemap-list">' 24 25 for(i in `{ls -dF $d^*/ $d^*.md $d^*.html $d^*.txt >[2]/dev/null | sed $dirfilter}) { 26 desc=`{get_file_title $i} 27 u=`{echo $i|sed 's!'$sitedir'!!; '$dirclean's!/index$!/!; '} 28 if(! ~ $#desc 0 && ! ~ $desc '') 29 desc=' - '$"desc 30 n=`{echo /$u|sed 's/[\-_]/ /g; s,.*/([^/]+)/?$,\1,'} 31 echo '<li><a href="'$u'">'^$"n^'</a>' $"desc '</li>' 32 echo $base_url^$u >> $tmpfile 33 echo '<url><loc>'$base_url^$u'</loc><lastmod>'^`{get_mdate $i}^'</lastmod></url>' >> $tmpfilex 34 if(test -d $i) 35 @{ listDir $i } 36 } 37 echo '</ul>' 38 } 39 } 40 41 42 fltr_cache listDir $sitedir/ 43 44 if(test -s $tmpfile) { 45 mv $tmpfile $sitedir/sitemap.txt & 46 } 47 if not if(test -f $tmpfile) 48 rm $tmpfile 49 50 if(test -s $tmpfilex) { 51 { 52 echo '<?xml version="1.0" encoding="UTF-8"?> 53 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' 54 55 cat $tmpfilex 56 rm $tmpfilex & 57 echo '</urlset>' 58 } | gzip > $sitedir/sitemap.gz & 59 #} > $sitedir/sitemap.xml & 60 } 61 if not if(test -f $tmpfilex) 62 rm $tmpfilex 63 64 %}