shithub: ugh

ref: ee19f22be32c725ab41c27918de1e6240d1866fc
dir: /bin/mksitemap/

View raw version
#!/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)
	}'