2022-03-10 07:21:54 +00:00
|
|
|
<h1>Site map</h1>
|
|
|
|
|
|
|
|
%{
|
|
|
|
tmpfile=/tmp/werc_sitemap_$pid.txt
|
2022-07-26 04:02:02 +00:00
|
|
|
tmpfilex=/tmp/werc_sitemapx_$pid.txt
|
2022-03-10 07:21:54 +00:00
|
|
|
saveddf=$dirfilter
|
2022-07-25 23:06:23 +00:00
|
|
|
filtereddirs=( images )
|
2022-03-10 07:21:54 +00:00
|
|
|
|
|
|
|
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/;'
|
|
|
|
|
|
|
|
fn get_mdate {
|
|
|
|
t=`{mtime $1}
|
|
|
|
t=`{date $t(1) | sed -e $MON2NUM -e 's/ ([0-9]) / 0\1 /g'} # Make sure day of the month is two digits.
|
|
|
|
echo $t(6)^'-'^$t(2)^'-'^$t(3)
|
|
|
|
}
|
|
|
|
|
2022-07-26 02:32:47 +00:00
|
|
|
fn get_children {
|
2022-07-26 03:05:25 +00:00
|
|
|
d=$1
|
2022-07-26 02:32:47 +00:00
|
|
|
children = `{ls -dF $d^*/ $d^*.md $d^*.html $d^*.txt >[2]/dev/null | sed $dirfilter}
|
|
|
|
echo $children
|
|
|
|
}
|
|
|
|
|
2022-03-10 07:21:54 +00:00
|
|
|
fn listDir {
|
|
|
|
d=$1
|
|
|
|
dirfilter=$saveddf
|
2022-07-26 02:32:47 +00:00
|
|
|
|
2022-03-10 07:21:54 +00:00
|
|
|
if(test -f $d/_werc/config)
|
|
|
|
. $d/_werc/config
|
|
|
|
|
|
|
|
if(~ $#perm_redir_to 0) {
|
2022-07-26 03:05:25 +00:00
|
|
|
siblings=`{get_children $d}
|
2022-07-26 02:32:47 +00:00
|
|
|
numsiblings = $#siblings
|
2022-07-26 03:05:25 +00:00
|
|
|
if(! ~ $numsiblings 0 && ! ~ $numsiblings 1){
|
|
|
|
echo '<ul class="sitemap-list">'
|
|
|
|
}
|
2022-07-26 02:32:47 +00:00
|
|
|
for(i in $siblings) {
|
2022-07-26 03:05:25 +00:00
|
|
|
ownchildren= `{get_children $i}
|
|
|
|
numownchildren=$#ownchildren
|
2022-07-25 23:06:23 +00:00
|
|
|
filename=`{get_file_title $i}
|
|
|
|
url=`{echo $i|sed 's!'$sitedir'!!; '$dirclean's!/index$!/!; '}
|
|
|
|
dirname=`{echo /$url|sed 's/[\-_]/ /g; s,.*/([^/]+)/?$,\1,'}
|
2022-07-26 03:05:25 +00:00
|
|
|
|
|
|
|
## Open list?
|
|
|
|
if(! ~ $numsiblings 1){
|
|
|
|
echo '<li>'
|
|
|
|
}
|
|
|
|
|
2022-07-25 23:06:23 +00:00
|
|
|
if(! ~ $#filename 0 && ! ~ $filename '') {
|
|
|
|
# filename=' — '$"filename
|
2022-07-26 03:05:25 +00:00
|
|
|
echo '<a href="'$url'">'^$"filename^'</a>'
|
2022-07-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
if not {
|
|
|
|
if(! ~ $"dirname $filtereddirs)
|
2022-07-26 03:05:25 +00:00
|
|
|
echo '<a href="'$url'">'^$"dirname^'</a>'
|
|
|
|
}
|
|
|
|
|
|
|
|
## echo $numsiblings' '$numownchildren
|
|
|
|
## ^ Useful for debugging purposes.
|
|
|
|
|
|
|
|
## Close list?
|
|
|
|
if(! ~ $numownchildren 1){
|
|
|
|
echo '</li>'
|
|
|
|
}
|
|
|
|
if not {
|
|
|
|
echo '/'
|
2022-07-25 23:06:23 +00:00
|
|
|
}
|
2022-07-26 03:05:25 +00:00
|
|
|
|
2022-07-25 23:06:23 +00:00
|
|
|
echo $base_url^$url >> $tmpfile
|
|
|
|
echo '<url><loc>'$base_url^$url'</loc><lastmod>'^`{get_mdate $i}^'</lastmod></url>' >> $tmpfilex
|
2022-03-10 07:21:54 +00:00
|
|
|
if(test -d $i)
|
|
|
|
@{ listDir $i }
|
|
|
|
}
|
2022-07-26 03:05:25 +00:00
|
|
|
if(! ~ $numsiblings 0 && ! ~ $numsiblings 1){
|
|
|
|
echo '</ul>'
|
|
|
|
}
|
2022-03-10 07:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fltr_cache listDir $sitedir/
|
|
|
|
|
|
|
|
if(test -s $tmpfile) {
|
|
|
|
mv $tmpfile $sitedir/sitemap.txt &
|
|
|
|
}
|
|
|
|
if not if(test -f $tmpfile)
|
|
|
|
rm $tmpfile
|
|
|
|
|
|
|
|
if(test -s $tmpfilex) {
|
|
|
|
{
|
|
|
|
echo '<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
|
|
|
|
|
|
|
|
cat $tmpfilex
|
|
|
|
rm $tmpfilex &
|
|
|
|
echo '</urlset>'
|
|
|
|
# TODO Enable automaic search engine update notification.
|
|
|
|
#hget 'http://google.com/ping?sitemap='^`{url_encode $base_url'/sitemap.gz'} > /dev/null
|
|
|
|
|
|
|
|
} | gzip > $sitedir/sitemap.gz &
|
|
|
|
#} > $sitedir/sitemap.xml &
|
|
|
|
}
|
|
|
|
if not if(test -f $tmpfilex)
|
|
|
|
rm $tmpfilex
|
|
|
|
|
|
|
|
%}
|