summaryrefslogtreecommitdiff
path: root/nav.sh
diff options
context:
space:
mode:
Diffstat (limited to 'nav.sh')
-rwxr-xr-xnav.sh37
1 files changed, 37 insertions, 0 deletions
diff --git a/nav.sh b/nav.sh
new file mode 100755
index 0000000..6cf5d08
--- /dev/null
+++ b/nav.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+set -e
+
+# usage: nav.sh <source dir> <output file>
+
+
+echo '<pre>' > $2 # starting <pre> tag
+echo '<!--title: Sitemap-->' >> $2 # util for smd.sh
+
+# initial tree generation
+
+tree -dfn --noreport -I 'css|error|favicon|fonts|js|media' $1 >> $2
+
+# remove leading path prefix
+
+sed 's;/var/www/distress\.network;;g' -i'' $2
+
+# link generation loop for each line
+
+grep -n '─ ' $2 | \
+while IFS='' read -r data ; do
+ LINE=$(echo $data | cut -f 1 -d :) ; # extract line number
+ FULL=$(echo $data | cut -f 2- -d /) ; # extract output path
+ NAME=$(echo $FULL | grep -o '[^/]*$') ; # extract page name (last field of path)
+
+ # at the line number, replace path with link to page
+
+ sed "${LINE}s;─ .*;──<a href=\"/${FULL}\">${NAME}</a>;" -i'' $2 ;
+done
+
+# replace starting blank line with root link
+
+sed '3s;.*;<a href="/">·</a>;' -i'' $2
+
+echo '</pre>' >> $2 # closing <pre> tag
+
+cat $2