openbsd-webzine/issues/tools/sitemap.sh

36 lines
801 B
Bash
Raw Normal View History

#!/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
ndd="$1"
2021-09-29 19:12:27 +00:00
# sitemap header
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
cd "$2"
2021-09-29 19:12:27 +00:00
find . -name \*.html | cut -d'/' -f2- | while read -r page
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)"
done
printf '%s' '</urlset>'
2021-09-29 19:12:27 +00:00
exit