sitemap.tpl (2751B)
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 filtereddirs=( images ) 8 9 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/;' 10 11 fn get_mdate { 12 t=`{mtime $1} 13 t=`{date $t(1) | sed -e $MON2NUM -e 's/ ([0-9]) / 0\1 /g'} # Make sure day of the month is two digits. 14 echo $t(6)^'-'^$t(2)^'-'^$t(3) 15 } 16 17 fn get_children { 18 d=$1 19 children = `{ls -dF $d^*/ $d^*.md $d^*.html $d^*.txt >[2]/dev/null | sed $dirfilter} 20 echo $children 21 } 22 23 fn listDir { 24 d=$1 25 dirfilter=$saveddf 26 27 if(test -f $d/_werc/config) 28 . $d/_werc/config 29 30 if(~ $#perm_redir_to 0) { 31 siblings=`{get_children $d} 32 numsiblings = $#siblings 33 if(! ~ $numsiblings 0 && ! ~ $numsiblings 1){ 34 echo '<ul class="sitemap-list">' 35 } 36 for(i in $siblings) { 37 ownchildren= `{get_children $i} 38 numownchildren=$#ownchildren 39 filename=`{get_file_title $i} 40 url=`{echo $i|sed 's!'$sitedir'!!; '$dirclean's!/index$!/!; '} 41 dirname=`{echo /$url|sed 's/[\-_]/ /g; s,.*/([^/]+)/?$,\1,'} 42 43 ## Open list? 44 if(! ~ $numsiblings 1){ 45 echo '<li>' 46 } 47 48 if(! ~ $#filename 0 && ! ~ $filename '') { 49 # filename=' — '$"filename 50 echo '<a href="'$url'">'^$"filename^'</a>' 51 } 52 if not { 53 if(! ~ $"dirname $filtereddirs) 54 echo '<a href="'$url'">'^$"dirname^'</a>' 55 } 56 57 ## echo $numsiblings' '$numownchildren 58 ## ^ Useful for debugging purposes. 59 60 ## Close list? 61 if(! ~ $numownchildren 1){ 62 echo '</li>' 63 } 64 if not { 65 echo '/' 66 } 67 68 echo $base_url^$url >> $tmpfile 69 echo '<url><loc>'$base_url^$url'</loc><lastmod>'^`{get_mdate $i}^'</lastmod></url>' >> $tmpfilex 70 if(test -d $i) 71 @{ listDir $i } 72 } 73 if(! ~ $numsiblings 0 && ! ~ $numsiblings 1){ 74 echo '</ul>' 75 } 76 } 77 } 78 79 80 fltr_cache listDir $sitedir/ 81 82 if(test -s $tmpfile) { 83 mv $tmpfile $sitedir/sitemap.txt & 84 } 85 if not if(test -f $tmpfile) 86 rm $tmpfile 87 88 if(test -s $tmpfilex) { 89 { 90 echo '<?xml version="1.0" encoding="UTF-8"?> 91 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' 92 93 cat $tmpfilex 94 rm $tmpfilex & 95 echo '</urlset>' 96 # TODO Enable automaic search engine update notification. 97 #hget 'http://google.com/ping?sitemap='^`{url_encode $base_url'/sitemap.gz'} > /dev/null 98 99 } | gzip > $sitedir/sitemap.gz & 100 #} > $sitedir/sitemap.xml & 101 } 102 if not if(test -f $tmpfilex) 103 rm $tmpfilex 104 105 %}