improve Atom feed - stagit-gopher - A git gopher frontend. (mirror)
git clone git://bitreich.org/stagit-gopher/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/stagit-gopher/
Log
Files
Refs
Tags
README
LICENSE
---
commit 51ecd71d5fd10327251c32d8a91e135945eaf20c
parent e3006c9373d8fff3e2e9d15a8b1990022064d4f6
Author: Hiltjo Posthuma 
Date:   Mon,  7 Dec 2015 18:58:39 +0100

improve Atom feed

Diffstat:
  M urmoms.c                            |      36 ++++++++++++++++---------------

1 file changed, 19 insertions(+), 17 deletions(-)
---
diff --git a/urmoms.c b/urmoms.c
@@ -152,7 +152,7 @@ printtime(FILE *fp, const git_time *intime)
         intm = gmtime(&t);
         strftime(out, sizeof(out), "%a %b %e %T %Y", intm);
 
-        fprintf(fp, "%s %c%02d%02d\n", out, sign, hours, minutes);
+        fprintf(fp, "%s %c%02d%02d", out, sign, hours, minutes);
 }
 
 void
@@ -399,24 +399,24 @@ printcommitatom(FILE *fp, git_commit *commit)
         int i, count;
         const char *scan, *eol, *summary;
 
-        fputs("", fp);
+        fputs("\n", fp);
 
         /* TODO: show tag when commit has it */
         git_oid_tostr(buf, sizeof(buf), git_commit_id(commit));
-        fprintf(fp, "%s", buf);
+        fprintf(fp, "%s\n", buf);
 
         sig = git_commit_author(commit);
 
         if (sig) {
                 fputs("", fp);
                 printtimez(fp, &sig->when);
-                fputs("", fp);
+                fputs("\n", fp);
         }
 
         if ((summary = git_commit_summary(commit))) {
-                fputs("", fp);
+                fputs("<title type=\"text\">", fp);
                 xmlencode(fp, summary, strlen(summary));
-                fputs("", fp);
+                fputs("\n", fp);
         }
 
         fputs("", fp);
@@ -451,15 +451,15 @@ printcommitatom(FILE *fp, git_commit *commit)
                 scan = *eol ? eol + 1 : NULL;
         }
         fputc('\n', fp);
-        fputs("", fp);
+        fputs("\n", fp);
         if (sig) {
                 fputs("", fp);
                 xmlencode(fp, sig->name, strlen(sig->name));
-                fputs("", fp);
+                fputs("\n", fp);
                 xmlencode(fp, sig->email, strlen(sig->email));
-                fputs("", fp);
+                fputs("\n\n", fp);
         }
-        fputs("", fp);
+        fputs("\n", fp);
 }
 
 int
@@ -470,12 +470,13 @@ writeatom(FILE *fp)
         git_commit *c = NULL;
         size_t i, m = 100; /* max */
 
-        fputs("", fp);
+        fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", fp);
+        fputs("<feed xmlns=\"http://www.w3.org/2005/Atom\">\n<title>", fp);
         xmlencode(fp, name, strlen(name));
-        fputs(", branch master", fp);
+        fputs(", branch master\n", fp);
 
         xmlencode(fp, description, strlen(description));
-        fputs("", fp);
+        fputs("\n", fp);
 
         git_revwalk_new(&w, repo);
         git_revwalk_push_head(w);
@@ -603,16 +604,17 @@ main(int argc, char *argv[])
         writefooter(fp);
         fclose(fp);
 
-        fp = efopen("atom.xml", "w+b");
-        writeatom(fp);
-        fclose(fp);
-
         fp = efopen("files.html", "w+b");
         writeheader(fp);
         writefiles(fp);
         writefooter(fp);
         fclose(fp);
 
+        /* Atom feed */
+        fp = efopen("atom.xml", "w+b");
+        writeatom(fp);
+        fclose(fp);
+
         /* cleanup */
         git_repository_free(repo);
         git_libgit2_shutdown();