1
0
Fork 0
repo2html/rss

70 lines
1.8 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# Generates an RSS feed from Git commit messages
#
# Copyright (C) 2012 Mike Gerwitz
#
# This file is part of ease.js.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
url="${1?Missing URL}"
count=10
# rss header
cat <<EOH
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>Mike Gerwitz's Thoughts and Ramblings</title>
<link>$url</link>
<description>
The miscellaneous thoughts and ramblings of a free software hacker
</description>
EOH
# output recent commits as entries (assuming no funny business in the output)
while read -r commit ts id subject; do
echo "Found $commit: $subject" >&2
# TODO: avoid HTML entities where browsers may decide not to render them (e.g.
# the title)
cat <<EOE
<item>
<title><![CDATA[$( ./msgfmt < <( echo "$subject"; echo ) )]]></title>
<link>
$( printf "%s/%(%Y/%m)T/%s.html" "$url" "$ts" "$id" )
</link>
<pubDate>$( date --date="1970-01-01 $ts sec" +%Y-%m-%d )</pubDate>
<description>
<![CDATA[
$( ./hash2html "$commit" )
]]>
</description>
</item>
EOE
done < <(
( git log --pretty='format:%h %at %f %s' && echo ) \
| head -n"$count"
)
# footer
cat <<EOF
</channel>
</rss>
EOF