blob: 6cf5d08dd2d79be1796e1702fe1d56260d92c618 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
|