commit 98712eadc99781315881a8a478ddf28020b849ba
parent cd71e96046587ae0b2297a3992db4c5b71a283c7
Author: Hayden Hamilton <hayden@hhvn.uk>
Date: Sat, 13 Jun 2026 09:17:50 +0100
Breadcrumb links for stagit repos
Diffstat:
5 files changed, 68 insertions(+), 15 deletions(-)
diff --git a/README b/README
@@ -31,8 +31,9 @@ www/chroot:
www/generate/src:
These scripts generate content in /var/www/htdocs/src.hhvn.uk
- - gomod: generates go.mod glue code
- - stagit: calls stagit
+ - gomod: generates go.mod glue code
+ - stagit: calls stagit
+ - stagit-breadcrumb: rewrites all stagit files to use www/generate/breadcrumb
repo:
These scrips manage /var/git
diff --git a/repo/hooks/post-receive b/repo/hooks/post-receive
@@ -1,4 +1,3 @@
#!/bin/rc
-www/generate/src/stagit
-www/generate/src/gomod
+www/generate/src/all
diff --git a/www/generate/breadcrumb b/www/generate/breadcrumb
@@ -27,18 +27,20 @@ if (! ~ $subdomain ()) {
curi = ''
for (e in $elems) {
- # special case for stagit
- if (~ $subdomain src && ~ $e log.html) {
- exit 0
- }
+ if (!~ $e '.') {
+ # special case for stagit
+ if (~ $subdomain src && ~ $e log.html) {
+ exit 0
+ }
- # we're done
- if (~ $e index.html) {
- exit 0
- }
+ # we're done
+ if (~ $e index.html) {
+ exit 0
+ }
- curi = $curi ^ '/' ^ $e
+ curi = $curi ^ '/' ^ $e
- text ' > '
- plink $curi `$nl{echo $e | sed 's/\.html$//'}
+ text ' > '
+ plink $curi `$nl{echo $e | sed 's/\.html$//'}
+ }
}
diff --git a/www/generate/src/all b/www/generate/src/all
@@ -0,0 +1,9 @@
+#!/bin/rc
+
+wwwdir = /var/www/htdocs/src.hhvn.uk
+newer = $wwwdir/.newer
+
+touch $newer
+www/generate/src/stagit
+www/generate/src/stagit-breadcrumb $newer
+www/generate/src/gomod
diff --git a/www/generate/src/stagit-breadcrumb b/www/generate/src/stagit-breadcrumb
@@ -0,0 +1,42 @@
+#!/bin/rc
+#
+# This script is very slow.
+# Hence the option to use find's -newer.
+# A file can be created before stagit runs,
+# and this script will only modify files created after.
+#
+# stagit will not modify files in the commit/ dir once created
+# It does however recreate everything at HEAD.
+# This isn't ideal.
+#
+# Most of the time taken in this script is most likely NOT cpu time.
+# It may be a good idea to run the main loop portion of this script in parallel.
+
+wwwdir = /var/www/htdocs/src.hhvn.uk
+newer = $1
+cd $wwwdir
+
+if (!~ $newer ()) {
+ fargs = (-newer $1)
+}
+
+fn breadcrumb {
+ printf %s '<h1>'
+ www/generate/breadcrumb $* | sed 's~&~\\\\\&~g'
+ printf %s '</h1>'
+}
+
+files = `$nl{find . $fargs -type f -name '*.html'}
+estatus = 0
+for (f in $files) {
+ printf %s 'BREADCRUMB ' ^ $f ^ '... '
+ breadcrumb = `''{breadcrumb $f hhvn.uk src}
+ awk -v breadcrumb=$breadcrumb '{ sub(/<h1>.*<\/h1>/, breadcrumb); sub(/<span class="desc">Repositories<\/span>/, breadcrumb) }1' < $f > $f.awk
+ if (~ $status 0) {
+ echo success
+ mv $f.awk $f
+ } else {
+ rm $f.awk
+ estatus = $status
+ }
+}