Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/rss
blob: 4ddcfc31f884da00b1c8bd1611321299955cceb8 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#
# Generates an RSS feed from Git commit messages
#
#  Copyright (C) 2012  Mike Gerwitz
#
#  This file is part of repo2html.
#
#  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/>.
# #

repotype="${1?Missing repository type}"
url="${2?Missing URL}"
count="${3:-0}"

# provide default message formatter if necessary
msgfmt="${msgfmt:-./msgfmt}"

# 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 hash commit ts id subject; do
  # ignore commits that begin with ':'
  [[ "$subject" == :* ]] && {
    echo "Ignoring $commit: $subject" >&2
    continue
  }

  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" -nP < <( echo "$subject"; echo ) )]]></title>
      <link>$(
        printf "%s/%s/%s.html" \
          "${url/%\/}" "$( ./tsdate "$ts" %Y/%m )" "$id"
        )
      </link>
      <pubDate>$( ./tsdate "$ts" %Y-%m-%d )</pubDate>
      <description>
        <![CDATA[
          $( ./"$repotype"/commit2html "$commit" )
        ]]>
      </description>
    </item>
EOE

  # continue until we reach the requested number (note that we increment before
  # the check, meaning that if the count is 0, then we will output every commit
  ((i++))
  [ "$i" -eq "$count" ] && {
    echo "Limit of $count reached." >&2
    break
  }
done

# footer
cat <<EOF
  </channel>
</rss>
EOF