Code Snippets and Patches of 2017

I needed a sitemap.xml for some static websites. So I thought, it's just an find with some options... an there it is:

#!/bin/bash

# url configuration
URL="https://mcmilk.de/"

# values: always hourly daily weekly monthly yearly never
FREQ="weekly"

# begin new sitemap
exec 1> sitemap.xml

# print head
echo '<?xml version="1.0" encoding="UTF-8"?>'
echo '<!-- generator="Milkys Sitemap Generator, https://github.com/mcmilk/sitemap-generator" -->'
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'

# print urls
IFS=$'\r\n' GLOBIGNORE='*' command eval "OPTIONS=($(cat $0.options))"
find . -type f "${OPTIONS[@]}" -printf "%TY-%Tm-%Td%p\n" | \
while read -r line; do
  DATE=${line:0:10}
  FILE=${line:12}
  echo "<url>"
  echo " <loc>${URL}${FILE}</loc>"
  echo " <lastmod>$DATE</lastmod>"
  echo " <changefreq>$FREQ</changefreq>"
  echo "</url>"
done

# print foot
echo "</urlset>"

sitemap.sh

Here are the options for it:

-prune
! -iname robots.txt
! -iname sitemap.\*
! -iname .\*
! -path ./css/\*
! -path ./js/\*
! -path ./img/\*
! -path ./fonts/\*

sitemap.sh.options

DOWNLOAD

The latest version can be fond on GitHub.

Last modified on 2017-01-06 at 15:23
netcup.de