Generate ATOM feed from a Git history
Created on 2023-06-05T01:13:25-05:00
Stanza to run everything:
git log --format="commit %H%nAuthor: %an%nSubject: %s%nDate: %aI%n%n%B" | gawk -f xml.awk | xmllint --format - > atom.xml
xml.awk:
# script to parse the output of git log --name-status
BEGIN{
RS="commit ";
FS="\n";
print "";
print "";
print "Example Feed ";
print "A subtitle. ";
print "";
print "";
print "urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6 ";
PrintedUpdateStamp=0;
}
NR>1{
StartComment=0;
CommentText = "";
CommitText = "";
SubjectText = "";
AuthorText = "";
DateText = "";
ChangesText = "";
isLast = 0;
for(i = 1; i <= NF; i++)
{
if (i==1) {CommitText = $i;}
if (match($i,/^Author/)) {
# remove "author :"
split($i,author1,": ");
split(author1[2],author2," <")
AuthorText = author2[1];
} else if (match($i, /^Subject/)) {
# remove "subject :"
split($i,dt,": ");
for (j = 2; j <= length(dt); j++) {
if (j > 2) SubjectText = SubjectText": ";
SubjectText = SubjectText""dt[j];
}
} else if (match($i,/^Date/)) {
StartComment=1; ln=i;
#remove "date :"
split($i,dt,": ");
DateText = dt[2];
#trim whitespaces
gsub(/^[ \t]+/,"",DateText);
} else if (StartComment==1 && i>ln) {
{CommentText=CommentText$i"\n"}
}
}
# steal the date from the most recent article
# XXX should rip it from the current date, though...
if (PrintedUpdateStamp==0) {
print ""DateText" ";
PrintedUpdateStamp=1;
}
print "\t";
print "\t\tgit:sha1:"CommitText" ";
print "\t\t"AuthorText" ";
print "\t\t"SubjectText" ";
print "\t\t"DateText" ";
print "\t\t";
{
cmd="multimarkdown -s --notransclude";
print CommentText |& cmd;
close(cmd, "to");
while ((cmd |& getline line) > 0) {
print line;
}
close(cmd);
}
#print CommentText;
print "\t\t ";
print "\t ";
}
END {
print " "
}