shithub: ugh

Download patch

ref: ee19f22be32c725ab41c27918de1e6240d1866fc
parent: bd34d60603cd062af02b0681c9e625b59f1893cd
author: kvik <kvik@a-b.xyz>
date: Wed Jul 29 20:36:33 EDT 2020

mksitemap: add sitemap generator

--- /dev/null
+++ b/bin/mksitemap
@@ -1,0 +1,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)
+	}'
--- a/mkfile
+++ b/mkfile
@@ -1,16 +1,25 @@
-articles = `{walk -f data/ | grep -v '^data/\.git/'}
-articles = ${articles:data/%=public/%}
-md =    `{{for(i in $articles) echo $i}| grep '\.md$'}
-txt =   `{{for(i in $articles) echo $i}| grep '\.txt$'}
-shtml = `{{for(i in $articles) echo $i}| grep '\.shtml$'}
-articles = ${md:   public/%.md=   public/%.html} \
-           ${shtml:public/%.shtml=public/%.html} \
-           $md $txt
+sources = `{walk -f data/ | grep -v '^data/\.git/'}
+pages = ${sources:data/%=public/%}
+md =    `{{for(i in $pages) echo $i}| grep '\.md$'}
+txt =   `{{for(i in $pages) echo $i}| grep '\.txt$'}
+shtml = `{{for(i in $pages) echo $i}| grep '\.shtml$'}
+pages = ${md:   public/%.md=   public/%.html} \
+        ${shtml:public/%.shtml=public/%.html} \
+        $md $txt \
+        public/sitemap.html
 
-all:V: $articles
+all:V: pages
 
+pages:V: $pages
+
 clean:V:
-	rm -rf $articles
+	rm -rf $pages
+
+public/sitemap.md: $sources
+	bin/mksitemap data/ >$target
+
+public/sitemap.html: public/sitemap.md
+	bin/md2html public/sitemap.md $target
 
 public/%.html: data/%.md
 	bin/md2html data/$stem.md $target