-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-menu.sh
executable file
·36 lines (31 loc) · 1.44 KB
/
update-menu.sh
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
#!/bin/bash
# Updates the navigation in all HTML files for Ohrenbaum. Yes. Amazing tech.
menufile=$(mktemp)
# use single quotes in the menufile, due to sed expression below
cat > $menufile <<MENU
<li data-irony='1'><a href='ueber.html'>Hintergrund</a>
<li data-irony='1'><a href='kindheit-und-jugend.html'>Geschichtliches</a>
<li data-irony='2'><a href='beirat.html'>Beirat</a>
<li data-irony='2'><a href='ausschreibungen.html'>Jobs</a>
<li data-irony='3'><a href='presse.html'>Pressemitteilungen</a>
<li data-irony='1'><a href='register.html'>Baumkataster</a>
<li data-irony='3'><a href='spenden.html'>Spenden</a>
<li data-irony='1'><a href='social-media.html'>Social Media</a>
<li data-irony='1'><a href='intranet.html'>Intarnet-Portal</a>
<li data-irony='0'><a href='impressum.html'>Impressum</a>
<li data-irony='0'><a href='impressum.html#datenschutz'>Datenschutz</a>
MENU
for html in *.html; do
start=$(grep -n "<nav><ul>" $html | cut -f1 -d:)
end=$(grep -n "</ul></nav>" $html | cut -f1 -d:)
if ! [[ $start =~ ^[0-9]+$ ]] && [[ $end =~ ^[0-9]+$ ]]; then
echo "$html: Start and end lines of navigation not properly detected. (I found '$start' and '$end')"
continue
fi
sponge=$(mktemp)
cat >$sponge \
<(head -n$(($start)) $html) \
<(sed "s/href='$html'/href='$html' class='active'/" $menufile) \
<(tail -n+$(($end)) $html)
cat <$sponge >$html
done