#!/bin/sh set -e # usage: nav.sh echo '
' > $2	# starting 
 tag
echo '' >> $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;─ .*;──${NAME};" -i'' $2 ;
done

# replace starting blank line with root link

sed '3s;.*;·;' -i'' $2

echo '
' >> $2 # closing
 tag

cat $2