#!/bin/sh set -e # usage: ./nav.sh # Copyright 2019-2022 DistressNetwork° # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . echo '
' > "$2"	# starting 
 tag
echo '' >> "$2"	# util for plain.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"

# hide tree characters for screen readers

sed 's;^\(.\+\)