minor improvements and add comments

This commit is contained in:
prx 2021-09-29 21:12:27 +02:00
parent e427ae522e
commit d1d6946dd0
1 changed files with 18 additions and 4 deletions

View File

@ -1,6 +1,18 @@
#!/bin/sh
# print to stdout a sitemap.xml
set -e
usage()
{
printf "usage $0 <domain.tld> <site_directory> %s\n"
exit 1
}
test $# -eq 2 || usage
ndd="$1"
# sitemap header
printf '%s\n' \
'<?xml version="1.0" encoding="UTF-8"?>
<urlset
@ -9,13 +21,15 @@ 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">'
# list all pages in site_directory and print last mod time
cd "$2"
find . -name \*.html | while read -r l
find . -name \*.html | cut -d'/' -f2- | while read -r page
do
link="$(printf "%s" ${l} | cut -d'/' -f2-)"
printf '<url><loc>%s</loc><lastmod>%s</lastmod></url>\n' \
"https://${ndd}/${link}"\
"$(date -r $(stat -f %m ${l}) +%Y-%m-%d)"
"https://${ndd}/${page}"\
"$(date -r $(stat -f %m ${l}) +%Y-%m-%d)"
done
printf '%s' '</urlset>'
exit