summaryrefslogtreecommitdiff
path: root/sitemap.sh
blob: 17ad69b48e6e1861353313807bfefe4cd62e9a97 (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
#!/bin/sh
set -e

# usage: ./sitemap.sh <target dir> <output xml>

# Copyright 2019-2021 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/>.

urlencode() (
	./urlencode | sed 's;%2F;/;g'
)

echo '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" 
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' > "$2"

find -L "$1" -type d | sort | sed -e 's;^\./;;' -e '\;/\(.git\|css\|error\|favicon\|fonts\|js\|media\);d' -e 's;$;/;' | \
while IFS='' read -r data ; do
	DATE=$(grep "last-modified" "${data}/index.html" | cut -f 4 -d \" | sed 's/ /T/' ) ;
	echo "$data" | urlencode | sed -e 's;^;<url><loc>https://;' -e "s;$;</loc><lastmod>${DATE}</lastmod></url>;" ;
	printf "\n" ;
done >> "$2"

echo '</urlset>' >> "$2"

cat "$2"