config: make empty js= omit script tag
[cgit.git] / ui-atom.c
blob5f4ad7df3f90b2cba6b5ae9a8632c42e4173d8c1
1 /* ui-atom.c: functions for atom feeds
3 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
9 #include "cgit.h"
10 #include "ui-atom.h"
11 #include "html.h"
12 #include "ui-shared.h"
14 static void add_entry(struct commit *commit, const char *host)
16 char delim = '&';
17 char *hex;
18 char *mail, *t, *t2;
19 struct commitinfo *info;
21 info = cgit_parse_commit(commit);
22 hex = oid_to_hex(&commit->object.oid);
23 html("<entry>\n");
24 html("<title>");
25 html_txt(info->subject);
26 html("</title>\n");
27 html("<updated>");
28 html_txt(show_date(info->committer_date, 0,
29 date_mode_from_type(DATE_ISO8601_STRICT)));
30 html("</updated>\n");
31 html("<author>\n");
32 if (info->author) {
33 html("<name>");
34 html_txt(info->author);
35 html("</name>\n");
37 if (info->author_email && !ctx.cfg.noplainemail) {
38 mail = xstrdup(info->author_email);
39 t = strchr(mail, '<');
40 if (t)
41 t++;
42 else
43 t = mail;
44 t2 = strchr(t, '>');
45 if (t2)
46 *t2 = '\0';
47 html("<email>");
48 html_txt(t);
49 html("</email>\n");
50 free(mail);
52 html("</author>\n");
53 html("<published>");
54 html_txt(show_date(info->author_date, 0,
55 date_mode_from_type(DATE_ISO8601_STRICT)));
56 html("</published>\n");
57 if (host) {
58 char *pageurl;
59 html("<link rel='alternate' type='text/html' href='");
60 html(cgit_httpscheme());
61 html_attr(host);
62 pageurl = cgit_pageurl(ctx.repo->url, "commit", NULL);
63 html_attr(pageurl);
64 if (ctx.cfg.virtual_root)
65 delim = '?';
66 html_attrf("%cid=%s", delim, hex);
67 html("'/>\n");
68 free(pageurl);
70 html("<id>");
71 html_txtf("urn:%s:%s", the_hash_algo->name, hex);
72 html("</id>\n");
73 html("<content type='text'>\n");
74 html_txt(info->msg);
75 html("</content>\n");
76 html("</entry>\n");
77 cgit_free_commitinfo(info);
81 void cgit_print_atom(char *tip, const char *path, int max_count)
83 char *host;
84 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
85 struct commit *commit;
86 struct rev_info rev;
87 int argc = 2;
88 bool first = true;
90 if (ctx.qry.show_all)
91 argv[1] = "--all";
92 else if (!tip)
93 argv[1] = ctx.qry.head;
95 if (path) {
96 argv[argc++] = "--";
97 argv[argc++] = path;
100 init_revisions(&rev, NULL);
101 rev.abbrev = DEFAULT_ABBREV;
102 rev.commit_format = CMIT_FMT_DEFAULT;
103 rev.verbose_header = 1;
104 rev.show_root_diff = 0;
105 rev.max_count = max_count;
106 setup_revisions(argc, argv, &rev, NULL);
107 prepare_revision_walk(&rev);
109 host = cgit_hosturl();
110 ctx.page.mimetype = "text/xml";
111 ctx.page.charset = "utf-8";
112 cgit_print_http_headers();
113 html("<feed xmlns='http://www.w3.org/2005/Atom'>\n");
114 html("<title>");
115 html_txt(ctx.repo->name);
116 if (path) {
117 html("/");
118 html_txt(path);
120 if (tip && !ctx.qry.show_all) {
121 html(", branch ");
122 html_txt(tip);
124 html("</title>\n");
125 html("<subtitle>");
126 html_txt(ctx.repo->desc);
127 html("</subtitle>\n");
128 if (host) {
129 char *fullurl = cgit_currentfullurl();
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");
137 html("<link rel='alternate' type='text/html' href='");
138 html_attrf("%s%s%s", cgit_httpscheme(), host, repourl);
139 html("'/>\n");
140 free(fullurl);
141 free(repourl);
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;
151 add_entry(commit, host);
152 release_commit_memory(the_repository->parsed_objects, commit);
153 commit->parents = NULL;
155 html("</feed>\n");
156 free(host);