Browse Source

really awful git-to-atom script

Brennen Bearnes 5 years ago
parent
commit
26dad28753
1 changed files with 48 additions and 0 deletions
  1. 48
    0
      git-feed.pl

+ 48
- 0
git-feed.pl View File

@@ -0,0 +1,48 @@
1
+#!/usr/bin/env perl
2
+
3
+use warnings;
4
+use strict;
5
+use 5.10.0;
6
+use XML::Atom::SimpleFeed;
7
+use HTML::Entities;
8
+
9
+my $book_url = "http://www.p1k3.com/userland-book/";
10
+my $feed_url = "http://www.p1k3.com/userland-book/feed.xml";
11
+
12
+my $log = `git log --pretty=format:"%H _ %ai _ %s"`;
13
+
14
+my $feed = XML::Atom::SimpleFeed->new(
15
+  title     => "userland: a book about the command line for humans",
16
+  link      => $book_url,
17
+  link      => { rel => 'self', href => $feed_url, },
18
+  # icon      => $self->favicon_url,
19
+  author    => 'Brennen Bearnes',
20
+  id        => $book_url,
21
+  generator => 'XML::Atom::SimpleFeed',
22
+  # updated   => iso_date(Wala::get_mtime($month_file)),
23
+);
24
+
25
+# content   => `git show $hash`,
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      => $book_url,
36
+    id        => $hash,
37
+    # content   => { content => `git show $hash`, type => 'text' },
38
+    content   => $formatted_commit,
39
+    updated   => $date,
40
+  );
41
+}
42
+
43
+print $feed->as_string;
44
+
45
+sub iso_date {
46
+  my ($time) = @_;
47
+  return strftime("%Y-%m-%dT%H:%M:%SZ", localtime($time));
48
+}

Loading…
Cancel
Save