summaryrefslogtreecommitdiff
path: root/sitemap.sh
diff options
context:
space:
mode:
Diffstat (limited to 'sitemap.sh')
-rwxr-xr-xsitemap.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/sitemap.sh b/sitemap.sh
new file mode 100755
index 0000000..faf535d
--- /dev/null
+++ b/sitemap.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+set -e
+
+# usage: ./sitemap.sh <target dir> <output xml>
+
+urlencode() (
+ # urlencode <string>
+
+ old_lc_collate=$LC_COLLATE
+ LC_COLLATE=C
+
+ length="${#1}"
+ i=1
+ while [ $i -le $length ] ; do
+ c=$(expr substr "$1" $i 1) ;
+ case $c in
+ ([a-zA-Z0-9./~_-]) printf "$c" ;;
+ (*) printf '%%%02X' "'$c" ;;
+ esac ;
+ true $((i=i+1)) ;
+ done
+
+ LC_COLLATE=$old_lc_collate
+)
+
+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
+
+echo "$(find -L $1 -type d | sort | sed -e 's;^\./;;' -e '\;/\(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/' ) ;
+ urlencode "$data" | sed -e 's;^;<url><loc>https://;' -e "s;$;</loc><lastmod>${DATE}</lastmod></url>;" ;
+ printf "\n" ;
+done >> $2
+
+echo '</urlset>' >> $2
+
+cat $2