Mirrored from GitHub

git clone https://github.com/christc4/sitemap.git

Jump to: README.md legacy-sitemap.tpl sitemap.tpl


README.md

1	# sitemap
2	
3	static sitemap using GNU tree
4	
5	`/werc/tpl/sitemap.tpl` is the default sitemap generator written in RC shell
6	
7	From my experience, it chugs when your site is massive
8	
9	`GNU tree` can generate a sitemap via `tree -H ./ > sitemap.html`
10	
11	You can get the GNU `tree` source from <https://salsa.debian.org/debian/tree-packaging> to modify core behaviour
12	
13	If you are on BSD you must compile the GNU version as the BSD version of `tree` does not support HTML output
14	
15	<hr>
16	
17	Thank you [risingthumb.xyz](https://risingthumb.xyz) for making it work universally for any werc site

legacy-sitemap.tpl

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	        # TODO Enable automaic search engine update notification.
59	        #hget 'http://google.com/ping?sitemap='^`{url_encode $base_url'/sitemap.gz'} > /dev/null
60	    
61	    } | gzip > $sitedir/sitemap.gz &
62	    #} > $sitedir/sitemap.xml &
63	}
64	if not if(test -f $tmpfilex)
65	    rm $tmpfilex
66	
67	%}

sitemap.tpl

1	<h1>Site map</h1>
2	
3	% a=`{pwd}^/sites/$SERVER_NAME
4	% tree -H . -I '*.md_werc|*.meta|*comments|*index.md|*tpl_werc' $a | sed -e 's|/'$a'||g' -e 's/\.md//g'