aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJune McEnroe2021-06-08 20:21:10 +0000
committerYigit Sever2023-07-21 03:03:50 +0300
commitde3ddb966cf47bd6a3cc39a00d1926da33b03c50 (patch)
tree16536591b9bfbc51f75405b378823d99f4332993
parenteb5a6288876789a5d8dfe9a8d61340d2efc60122 (diff)
downloadcgit-de3ddb966cf47bd6a3cc39a00d1926da33b03c50.tar.gz
cgit-de3ddb966cf47bd6a3cc39a00d1926da33b03c50.tar.bz2
cgit-de3ddb966cf47bd6a3cc39a00d1926da33b03c50.zip
ui-atom: generate valid Atom feeds
Fixes several RFC 4287 violations: > 4.1.1. The "atom:feed" Element > o atom:feed elements MUST contain exactly one atom:id element. > o atom:feed elements SHOULD contain one atom:link element with a rel > attribute value of "self". This is the preferred URI for > retrieving Atom Feed Documents representing this Atom feed. > o atom:feed elements MUST contain exactly one atom:updated element. An atom:id element is generated from cgit_currentfullurl(), and an atom:link element with a rel attribute of "self" is generated with the same URL. An atom:updated element is generated from the date of the first commit in the revision walk. > 4.1.2. The "atom:entry" Element > o atom:entry elements MUST NOT contain more than one atom:content > element. The second atom:content element with the type of "xhtml" is removed. > 4.2.6. The "atom:id" Element > Its content MUST be an IRI, as defined by [RFC3987]. Note that the > definition of "IRI" excludes relative references. Though the IRI > might use a dereferencable scheme, Atom Processors MUST NOT assume it > can be dereferenced. The atom:id elements for commits now use URNs in the "sha1" or "sha256" namespaces. Although these are not registered URN namespaces, they see use in the wild, for instance as part of magnet URIs. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--ui-atom.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/ui-atom.c b/ui-atom.c
index 1056f36..541660d 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -67,17 +67,12 @@ static void add_entry(struct commit *commit, const char *host)
67 html("'/>\n"); 67 html("'/>\n");
68 free(pageurl); 68 free(pageurl);
69 } 69 }
70 htmlf("<id>%s</id>\n", hex); 70 html("<id>");
71 html_txtf("urn:%s:%s", the_hash_algo->name, hex);
72 html("</id>\n");
71 html("<content type='text'>\n"); 73 html("<content type='text'>\n");
72 html_txt(info->msg); 74 html_txt(info->msg);
73 html("</content>\n"); 75 html("</content>\n");
74 html("<content type='xhtml'>\n");
75 html("<div xmlns='http://www.w3.org/1999/xhtml'>\n");
76 html("<pre>\n");
77 html_txt(info->msg);
78 html("</pre>\n");
79 html("</div>\n");
80 html("</content>\n");
81 html("</entry>\n"); 76 html("</entry>\n");
82 cgit_free_commitinfo(info); 77 cgit_free_commitinfo(info);
83} 78}
@@ -90,6 +85,7 @@ void cgit_print_atom(char *tip, const char *path, int max_count)
90 struct commit *commit; 85 struct commit *commit;
91 struct rev_info rev; 86 struct rev_info rev;
92 int argc = 2; 87 int argc = 2;
88 bool first = true;
93 89
94 if (ctx.qry.show_all) 90 if (ctx.qry.show_all)
95 argv[1] = "--all"; 91 argv[1] = "--all";
@@ -130,15 +126,28 @@ void cgit_print_atom(char *tip, const char *path, int max_count)
130 html_txt(ctx.repo->desc); 126 html_txt(ctx.repo->desc);
131 html("</subtitle>\n"); 127 html("</subtitle>\n");
132 if (host) { 128 if (host) {
129 char *fullurl = cgit_currentfullurl();
133 char *repourl = cgit_repourl(ctx.repo->url); 130 char *repourl = cgit_repourl(ctx.repo->url);
131 html("<id>");
132 html_txtf("%s%s%s", cgit_httpscheme(), host, fullurl);
133 html("</id>\n");
134 html("<link rel='self' href='");
135 html_attrf("%s%s%s", cgit_httpscheme(), host, fullurl);
136 html("'/>\n");
134 html("<link rel='alternate' type='text/html' href='"); 137 html("<link rel='alternate' type='text/html' href='");
135 html(cgit_httpscheme()); 138 html_attrf("%s%s%s", cgit_httpscheme(), host, repourl);
136 html_attr(host);
137 html_attr(repourl);
138 html("'/>\n"); 139 html("'/>\n");
140 free(fullurl);
139 free(repourl); 141 free(repourl);
140 } 142 }
141 while ((commit = get_revision(&rev)) != NULL) { 143 while ((commit = get_revision(&rev)) != NULL) {
144 if (first) {
145 html("<updated>");
146 html_txt(show_date(commit->date, 0,
147 date_mode_from_type(DATE_ISO8601_STRICT)));
148 html("</updated>\n");
149 first = false;
150 }
142 add_entry(commit, host); 151 add_entry(commit, host);
143 free_commit_buffer(the_repository->parsed_objects, commit); 152 free_commit_buffer(the_repository->parsed_objects, commit);
144 free_commit_list(commit->parents); 153 free_commit_list(commit->parents);