shithub: shithub

Download patch

ref: c5847bcde2ed8d1e5891e79b186a14e46cfa0bfa
parent: 7c3ef1d4f6ff9b6dfcc96d4b0bce2c93cdc1d069
author: phil9 <[email protected]>
date: Tue Nov 16 11:57:30 EST 2021

implement a breadcrumb bar

	add a breadcrumb bar to the `browse` and `view` pages to allow
	for easier navigation.

--- a/common.rc
+++ b/common.rc
@@ -105,6 +105,26 @@
 	'
 }
 
+fn breadcrumb {
+	awk '
+	function breadcrumb(baseurl, repo, p) {
+		printf "» <a href='%s'>%s</a>\n", baseurl, repo;
+		n = split(p, a, "/");
+		q = "";
+		for (i = 2; i <= n; i++) {
+			q = sprintf("%s/%s", q, a[i]);
+			printf "&nbsp;/&nbsp;";
+			if (i == n)
+				printf "%s\n", a[i];
+			else
+				printf "<a href='%s%s'>%s</a>\n", baseurl, q, a[i];
+		}
+	}
+	
+	{ breadcrumb($1, $2, $3); }
+	'
+}
+
 fn prelude {
 	puser=$1
 	prepo=$2
--- a/files
+++ b/files
@@ -46,7 +46,9 @@
 
 if (! ~ $#dir 0) cd .$dir
 
-echo '<p><div id="code">'
+echo '<p>' 
+if (! ~ $#dir 0) echo /$gituser/$repo/browse/$hash $repo $dir |breadcrumb
+echo '<div id="code">'
 for(f in `$nl{ls}){
 echo '<!-- f: ' $f ' -->'
 	url=`$nl{echo -n $f | urlencode}
--- a/view
+++ b/view
@@ -31,6 +31,9 @@
 	<b>ref:</b> <a href="'/$gituser/$repo/browse/$hash/'">'$hash'</a><br/>
 	<b>raw:</b>	<a href="'/$gituser/$repo/viewraw/$hash/$file'">view</a>
 	</p>'
+
+echo /$gituser/$repo/browse/$hash $repo /$file |breadcrumb
+
 if(test -f $file){
 	type=`{file -m $file}
 	switch($type){