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