~kvik/ugh

ref: ee19f22be32c725ab41c27918de1e6240d1866fc ugh/bin/mksitemap -rwxr-xr-x 585 bytes
ee19f22bkvik mksitemap: add sitemap generator 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/rc -e
rfork e
flagfmt = ''; args = 'directory'
eval `''{aux/getflags $*} || exec aux/usage
if(! ~ $#* 1) exec aux/usage

cd $1
walk -f -emp |
	grep '\.(md|txt)' |
	sort -nr |
	awk '
	BEGIN{
		print "# Sitemap"
		print
		print "List of all pages, ordered by modification time."
		print
	}

	$2 !~ /^\.(git|hg)/ {linkto($2)}

	function title(file){
		getline t <file
		if(file ~ /\.md$/ && t ~ /^#[ ]+/)
			sub(/^#[ ]+/, "", t)
		return t
	}
	function linkto(file){
		link = file
		if(file ~ /\.md$/)
			sub(/\.md$/, ".html", link)
		printf("- [%s](%s)\n", title(file), link)
	}'