A bin/mksitemap => bin/mksitemap +32 -0
@@ 0,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)
+ }'
M mkfile => mkfile +19 -10
@@ 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