git ssb

0+

cel / gitfeed



Commit c1f121b32b2ca8f08f6e30509d49c2f73ef93bb8

Initial commit

Charles Lehner committed on 5/14/2015, 7:03:43 PM

Files changed

feed.shadded
xml.awkadded
feed.shView
@@ -1,0 +1,41 @@
1 +#!/bin/sh
2 +
3 +: ${SITE_URL:=./}
4 +: ${SITE_TITLE:=My Cool Site}
5 +: ${SITE_AUTHOR:=$(grep $(id -u) /etc/passwd | cut -d: -f 5 | cut -d, -f1)}
6 +: ${SITE_ID:=$(cat site_id || echo urn:uuid:$(uuidgen) | tee site_id)}
7 +: ${FEED_ENTRIES:=15}
8 +: ${FEED_WIDTH:=80}
9 +
10 +cat <<EOF
11 +<?xml version="1.0" encoding="utf-8"?>
12 + <feed xmlns="http://www.w3.org/2005/Atom">
13 + <title>$SITE_TITLE</title>
14 + <link rel="alternate" type="text/html" href="$SITE_URL"/>
15 + <link rel="self" type="application/rss+xml" href="${SITE_URL}feed.xml"/>
16 + <updated>$(date --iso-8601=seconds | sed 's/..$/:&/')</updated>
17 + <author>
18 + <name>$SITE_AUTHOR</name>
19 + </author>
20 + <id>$SITE_ID</id>
21 +
22 +EOF
23 +
24 +content_delim=$(uuidgen)
25 +
26 +git log -$FEED_ENTRIES --stat=$FEED_WIDTH --format=format:"entry $content_delim
27 +title %s
28 +id %H
29 +name %aN
30 +email %aE
31 +updated %ai
32 +content $content_delim
33 +commit %H
34 +
35 +%B
36 +stat $content_delim" | awk -f xml.awk -v site="$SITE_URL"
37 +
38 +cat <<EOF
39 + </feed>
40 +
41 +EOF
xml.awkView
@@ -1,0 +1,83 @@
1 +function escape_html(text) {
2 + gsub(/&/, "\\&amp;", text)
3 + gsub(/</, "\\&lt;", text)
4 + gsub(/>/, "\\&gt;", text)
5 + gsub(/"/, "\\&quot;", text)
6 + return text
7 +}
8 +
9 +function get_value() {
10 + sub(/^[^ ]* */, "")
11 + return $0
12 +}
13 +
14 +function end() {
15 + print "&lt;/pre&gt;</content>"
16 + print "</entry>"
17 +}
18 +
19 +$1 == "entry" {
20 + if (in_content && $2 == end_of_content) {
21 + in_content = 0
22 + in_stat = 0
23 + end()
24 + }
25 +
26 + title = ""
27 + id = ""
28 + name = ""
29 + email = ""
30 + updated = ""
31 +
32 + next
33 +}
34 +
35 +$1 == "stat" && $2 == end_of_content {
36 + in_stat = 1
37 + next
38 +}
39 +
40 +$1 == "content" {
41 + end_of_content = $2
42 + print "<entry>"
43 + print " <title>" escape_html(title) "</title>"
44 + print " <id>" id "</id>"
45 + print " <author>"
46 + print " <name>" escape_html(name) "</name>"
47 + print " <email>" escape_html(email) "</email>"
48 + print " </author>"
49 + print " <updated>" escape_html(updated) "</updated>"
50 + printf " <content type=\"html\">&lt;pre&gt;"
51 + in_content = 1
52 + next
53 +}
54 +
55 +in_stat && /^ [^ ]* *\|/ {
56 + sub(/[^ ][^ ]*/, "<a href=\"" site "&\">&</a>")
57 +}
58 +
59 +in_stat && / \+*-*$/ {
60 + sub(/ \++/, "<span style=\"color:green\">&</span>")
61 + sub(/-+$/, "<span style=\"color:red\">&</span>")
62 +}
63 +
64 +in_content {
65 + print escape_html($0)
66 + next
67 +}
68 +
69 +$1 == "title" { title = get_value() }
70 +$1 == "name" { name = get_value() }
71 +$1 == "email" { email = get_value() }
72 +$1 == "id" {
73 + id = get_value()
74 + id = site ".git/objects/" substr(id, 1, 2) "/" substr(id, 3)
75 +}
76 +$1 == "updated" {
77 + updated = $2 "T" $3 substr($4, 1, 3) ":" substr($4, 3, 2)
78 +}
79 +
80 +END {
81 + if (in_content)
82 + end()
83 +}

Built with git-ssb-web