/
generate-sitemap.sh
executable file
·56 lines (50 loc) · 1.49 KB
/
generate-sitemap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/zsh
#
# File: generate-sitemap.sh
#
# Created: Wednesday, April 2 2008 by Alex Ott
#
export LC_TIME=C
FILE=sitemap.xml
echo '<?xml version="1.0" encoding="UTF-8"?>' > $FILE
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' >> $FILE
# TODO:
# - skip news part
# - skip common/emacs/ part
LSCMD=ls
if [ "$(uname)" = "Darwin" ]; then
LSCMD=gls
fi
for file in **/*.html **/*.pdf ; do
DFILE=`dirname "$file"`
MFILE=$DFILE/`basename "$file" .html`.muse
if [ -L "$file" ] ; then
echo "$file is symbolic link!"
elif [ -L "$DFILE" ] ; then
echo "directory is symbolic link!"
elif [ -f "$MFILE" ]; then
case "$file" in
de/*)
echo "skip german pages $MFILE"
;;
*)
MTIME=$($LSCMD -l --time-style='full-iso' "$MFILE" |awk '{print $6}')
echo "MTIME=$MTIME MFILE=$MFILE"
echo "<url><loc>http://alexott.net/$file</loc>\n<lastmod>$MTIME</lastmod></url>" >> $FILE
;;
esac
else
case "$file" in
*/news/*)
echo "skip news file $file"
;;
common/emacs/*)
echo "skip emacs config $file"
;;
*)
$LSCMD -l --time-style='full-iso' "$file" |awk '{print "<url><loc>http://alexott.net/" $9 "</loc>\n<lastmod>" $6 "</lastmod></url>"}' >> $FILE
;;
esac
fi
done
echo '</urlset>' >> $FILE