Browse Source

add feed generation

Brennen Bearnes 4 years ago
parent
commit
ad6607e72c
1 changed files with 47 additions and 0 deletions
  1. 47
    0
      git-feed.pl

+ 47
- 0
git-feed.pl View File

@@ -0,0 +1,47 @@
1
+#!/usr/bin/env perl
2
+
3
+# TODO: this really just ought to be a general-purpose utility
4
+
5
+use warnings;
6
+use strict;
7
+use 5.10.0;
8
+use XML::Atom::SimpleFeed;
9
+use HTML::Entities;
10
+
11
+my $page_url = "http://tilde.club/~brennen/";
12
+my $feed_url = "http://tilde.club/~brennen/feed.xml";
13
+
14
+my $log = `git log -10 --pretty=format:"%H _ %ai _ %s"`;
15
+
16
+my $feed = XML::Atom::SimpleFeed->new(
17
+  title     => "Brennen's tilde.club page",
18
+  link      => $page_url,
19
+  link      => { rel => 'self', href => $feed_url, },
20
+  author    => 'Brennen Bearnes',
21
+  id        => $page_url,
22
+  generator => 'XML::Atom::SimpleFeed',
23
+  # updated   => iso_date(Wala::get_mtime($month_file)),
24
+);
25
+
26
+while ($log =~ m/^([a-z0-9]+) _ (.*) _ (.*)$/gm) {
27
+  my $hash = $1;
28
+  my $full_commit = `git show $hash`;
29
+  my $formatted_commit = '<pre>' . encode_entities($full_commit) . '</pre>';
30
+  my $date = $2;
31
+  my $subj = $3;
32
+
33
+  $feed->add_entry(
34
+    title     => $subj,
35
+    link      => $page_url,
36
+    id        => $hash,
37
+    content   => $formatted_commit,
38
+    updated   => $date,
39
+  );
40
+}
41
+
42
+print $feed->as_string;
43
+
44
+sub iso_date {
45
+  my ($time) = @_;
46
+  return strftime("%Y-%m-%dT%H:%M:%SZ", localtime($time));
47
+}