Skip to content

Instantly share code, notes, and snippets.

@yarwelp
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yarwelp/35f781d926af1b9f090c to your computer and use it in GitHub Desktop.
Save yarwelp/35f781d926af1b9f090c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Run as www-auto, e.g. `sudo -u www-auto ./sitemap.sh'
cd /usr/local/www/net.erikano.www && touch sitemap.htm &&\
(
cat <<HTMLBegin
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sitemap of www.erikano.net</title>
</head>
<body>
<header>
<h1>Sitemap of www.erikano.net</h1>
<h2><a href="/">www.erikano.net</a></h2>
</header>
HTMLBegin
echo "<section><header><h1>Human authored</h1></header>"
echo "<table><tr><th>Last modified</th><th>URL Path name</th><th>Title</th></tr>"
TZ=Europe/Oslo find . -user erikano -name \*.htm \
-exec stat -f "<tr><td>%Sm</td><td><a href=\"%N\">%N</a></td>" \
-t "%Y-%m-%dT%H:%M:%S%z" {} \; \
-exec gawk -v IGNORECASE=1 -v RS='</title' \
'RT{gsub(/.*<title[^>]*>/,"");print "<td>" $0 "</td></tr>";exit}' {} \; \
| awk '!(NR%2){print p$0}{p=$0}' | sed -e 's/\.\//\//g' -e 's/index.htm//g' \
| sort -nr
echo "</table></section>"
echo "<section><header><h1>System generated</h1></header>"
echo "<table><tr><th>Last modified</th><th>URL Path name</th><th>Title</th></tr>"
TZ=UTC find . -user www-auto -name \*.htm \
-exec stat -f "<tr><td>%Sm</td><td><a href=\"%N\">%N</a></td>" \
-t "%Y-%m-%dT%H:%M:%S%z" {} \; \
-exec gawk -v IGNORECASE=1 -v RS='</title' \
'RT{gsub(/.*<title[^>]*>/,"");print "<td>" $0 "</td></tr>";exit}' {} \; \
| awk '!(NR%2){print p$0}{p=$0}' | sed -e 's/\.\//\//g' -e 's/index.htm//g' \
| sort -nr
echo "</table></section>"
cat <<HTMLEnd
</table>
</body>
</html>
HTMLEnd
) > sitemap.htm.new && mv sitemap.htm.new sitemap.htm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment