blob: 50eaa82d6146887fb664923ad823c7e6731273b7 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#!/bin/sh
set -e
# usage: nav.sh <source dir> <output file>
# Copyright 2019-2020 DistressNetwork° <uplink@distress.network>
#
# 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 <http://www.gnu.org/licenses/>.
echo '<pre>' > $2 # starting <pre> tag
echo '<!--title: Sitemap — DistressNetwork°-->' >> $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="/" aria-label="root">·</a>;' -i'' $2
# hide tree characters for screen readers
sed 's;^\(.\+\)<a;<span aria-hidden="true">\1</span><a;1' -i'' $2
echo '</pre>' >> $2 # closing <pre> tag
cat $2
|