Blame


1 e7e5fa49 2022-12-30 thomas {!
2 e7e5fa49 2022-12-30 thomas /*
3 e7e5fa49 2022-12-30 thomas * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 e7e5fa49 2022-12-30 thomas * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
5 e7e5fa49 2022-12-30 thomas *
6 e7e5fa49 2022-12-30 thomas * Permission to use, copy, modify, and distribute this software for any
7 e7e5fa49 2022-12-30 thomas * purpose with or without fee is hereby granted, provided that the above
8 e7e5fa49 2022-12-30 thomas * copyright notice and this permission notice appear in all copies.
9 e7e5fa49 2022-12-30 thomas *
10 e7e5fa49 2022-12-30 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 e7e5fa49 2022-12-30 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 e7e5fa49 2022-12-30 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 e7e5fa49 2022-12-30 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 e7e5fa49 2022-12-30 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 e7e5fa49 2022-12-30 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 e7e5fa49 2022-12-30 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 e7e5fa49 2022-12-30 thomas */
18 e7e5fa49 2022-12-30 thomas
19 e7e5fa49 2022-12-30 thomas #include <sys/types.h>
20 e7e5fa49 2022-12-30 thomas #include <sys/queue.h>
21 e7e5fa49 2022-12-30 thomas
22 d6795e9f 2022-12-30 thomas #include <ctype.h>
23 e7e5fa49 2022-12-30 thomas #include <event.h>
24 e7e5fa49 2022-12-30 thomas #include <stdint.h>
25 e7e5fa49 2022-12-30 thomas #include <stdlib.h>
26 e7e5fa49 2022-12-30 thomas #include <string.h>
27 e7e5fa49 2022-12-30 thomas #include <imsg.h>
28 e7e5fa49 2022-12-30 thomas
29 e7e5fa49 2022-12-30 thomas #include "proc.h"
30 e7e5fa49 2022-12-30 thomas
31 e7e5fa49 2022-12-30 thomas #include "gotwebd.h"
32 e7e5fa49 2022-12-30 thomas #include "tmpl.h"
33 e7e5fa49 2022-12-30 thomas
34 d6795e9f 2022-12-30 thomas static inline int rss_tag_item(struct template *, struct repo_tag *);
35 d6795e9f 2022-12-30 thomas static inline int rss_author(struct template *, char *);
36 d6795e9f 2022-12-30 thomas
37 e7e5fa49 2022-12-30 thomas static int
38 e7e5fa49 2022-12-30 thomas gotweb_render_age(struct template *tp, time_t time, int ref_tm)
39 e7e5fa49 2022-12-30 thomas {
40 e7e5fa49 2022-12-30 thomas const struct got_error *err;
41 e7e5fa49 2022-12-30 thomas char *age;
42 e7e5fa49 2022-12-30 thomas int r;
43 e7e5fa49 2022-12-30 thomas
44 e7e5fa49 2022-12-30 thomas err = gotweb_get_time_str(&age, time, ref_tm);
45 e7e5fa49 2022-12-30 thomas if (err)
46 e7e5fa49 2022-12-30 thomas return 0;
47 e7e5fa49 2022-12-30 thomas r = tp->tp_puts(tp, age);
48 e7e5fa49 2022-12-30 thomas free(age);
49 e7e5fa49 2022-12-30 thomas return r;
50 e7e5fa49 2022-12-30 thomas }
51 e7e5fa49 2022-12-30 thomas
52 e7e5fa49 2022-12-30 thomas !}
53 e7e5fa49 2022-12-30 thomas
54 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_header(struct template *tp) }}
55 e7e5fa49 2022-12-30 thomas {!
56 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
57 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
58 e7e5fa49 2022-12-30 thomas struct querystring *qs = c->t->qs;
59 e7e5fa49 2022-12-30 thomas struct gotweb_url u_path;
60 3191e256 2022-12-30 thomas const char *prfx = c->document_uri;
61 e7e5fa49 2022-12-30 thomas const char *css = srv->custom_css;
62 e7e5fa49 2022-12-30 thomas
63 e7e5fa49 2022-12-30 thomas memset(&u_path, 0, sizeof(u_path));
64 e7e5fa49 2022-12-30 thomas u_path.index_page = -1;
65 e7e5fa49 2022-12-30 thomas u_path.page = -1;
66 e7e5fa49 2022-12-30 thomas u_path.action = SUMMARY;
67 e7e5fa49 2022-12-30 thomas !}
68 e7e5fa49 2022-12-30 thomas <!doctype html>
69 e7e5fa49 2022-12-30 thomas <html>
70 e7e5fa49 2022-12-30 thomas <head>
71 e7e5fa49 2022-12-30 thomas <meta charset="utf-8" />
72 e7e5fa49 2022-12-30 thomas <title>{{ srv->site_name }}</title>
73 e7e5fa49 2022-12-30 thomas <meta name="viewport" content="initial-scale=.75" />
74 e7e5fa49 2022-12-30 thomas <meta name="msapplication-TileColor" content="#da532c" />
75 e7e5fa49 2022-12-30 thomas <meta name="theme-color" content="#ffffff"/>
76 e7e5fa49 2022-12-30 thomas <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
77 e7e5fa49 2022-12-30 thomas <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
78 e7e5fa49 2022-12-30 thomas <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
79 e7e5fa49 2022-12-30 thomas <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
80 e7e5fa49 2022-12-30 thomas <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
81 e7e5fa49 2022-12-30 thomas <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
82 e7e5fa49 2022-12-30 thomas </head>
83 e7e5fa49 2022-12-30 thomas <body>
84 e7e5fa49 2022-12-30 thomas <div id="gw_body">
85 e7e5fa49 2022-12-30 thomas <div id="header">
86 e7e5fa49 2022-12-30 thomas <div id="got_link">
87 e7e5fa49 2022-12-30 thomas <a href="{{ srv->logo_url }}" target="_blank">
88 e7e5fa49 2022-12-30 thomas <img src="{{ prfx }}{{ srv->logo }}" />
89 e7e5fa49 2022-12-30 thomas </a>
90 e7e5fa49 2022-12-30 thomas </div>
91 e7e5fa49 2022-12-30 thomas </div>
92 e7e5fa49 2022-12-30 thomas <div id="site_path">
93 e7e5fa49 2022-12-30 thomas <div id="site_link">
94 e7e5fa49 2022-12-30 thomas <a href="?index_page={{ printf "%d", qs->index_page }}">
95 e7e5fa49 2022-12-30 thomas {{ srv->site_link }}
96 e7e5fa49 2022-12-30 thomas </a>
97 e7e5fa49 2022-12-30 thomas {{ if qs->path }}
98 e7e5fa49 2022-12-30 thomas {! u_path.path = qs->path; !}
99 e7e5fa49 2022-12-30 thomas {{ " / " }}
100 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
101 e7e5fa49 2022-12-30 thomas {{ qs->path }}
102 e7e5fa49 2022-12-30 thomas </a>
103 e7e5fa49 2022-12-30 thomas {{ end }}
104 e7e5fa49 2022-12-30 thomas {{ if qs->action != INDEX }}
105 e7e5fa49 2022-12-30 thomas {{ " / " }}{{ gotweb_action_name(qs->action) }}
106 e7e5fa49 2022-12-30 thomas {{ end }}
107 e7e5fa49 2022-12-30 thomas </div>
108 e7e5fa49 2022-12-30 thomas </div>
109 e7e5fa49 2022-12-30 thomas <div id="content">
110 e7e5fa49 2022-12-30 thomas {{ end }}
111 e7e5fa49 2022-12-30 thomas
112 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_footer(struct template *tp) }}
113 e7e5fa49 2022-12-30 thomas {!
114 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
115 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
116 e7e5fa49 2022-12-30 thomas !}
117 e7e5fa49 2022-12-30 thomas <div id="site_owner_wrapper">
118 e7e5fa49 2022-12-30 thomas <div id="site_owner">
119 e7e5fa49 2022-12-30 thomas {{ if srv->show_site_owner }}
120 e7e5fa49 2022-12-30 thomas {{ srv->site_owner }}
121 e7e5fa49 2022-12-30 thomas {{ end }}
122 e7e5fa49 2022-12-30 thomas </div>
123 e7e5fa49 2022-12-30 thomas </div>
124 e7e5fa49 2022-12-30 thomas </div>
125 e7e5fa49 2022-12-30 thomas </div>
126 e7e5fa49 2022-12-30 thomas </body>
127 e7e5fa49 2022-12-30 thomas </html>
128 e7e5fa49 2022-12-30 thomas {{ end }}
129 e7e5fa49 2022-12-30 thomas
130 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
131 e7e5fa49 2022-12-30 thomas {!
132 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
133 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
134 e7e5fa49 2022-12-30 thomas !}
135 e7e5fa49 2022-12-30 thomas <div id="index_header">
136 e7e5fa49 2022-12-30 thomas <div id="index_header_project">
137 e7e5fa49 2022-12-30 thomas Project
138 e7e5fa49 2022-12-30 thomas </div>
139 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_description }}
140 e7e5fa49 2022-12-30 thomas <div id="index_header_description">
141 e7e5fa49 2022-12-30 thomas Description
142 e7e5fa49 2022-12-30 thomas </div>
143 e7e5fa49 2022-12-30 thomas {{ end }}
144 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_owner }}
145 e7e5fa49 2022-12-30 thomas <div id="index_header_owner">
146 e7e5fa49 2022-12-30 thomas Owner
147 e7e5fa49 2022-12-30 thomas </div>
148 e7e5fa49 2022-12-30 thomas {{ end }}
149 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_age }}
150 e7e5fa49 2022-12-30 thomas <div id="index_header_age">
151 e7e5fa49 2022-12-30 thomas Last Change
152 e7e5fa49 2022-12-30 thomas </div>
153 e7e5fa49 2022-12-30 thomas {{ end }}
154 e7e5fa49 2022-12-30 thomas </div>
155 e7e5fa49 2022-12-30 thomas {{ end }}
156 e7e5fa49 2022-12-30 thomas
157 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
158 e7e5fa49 2022-12-30 thomas {!
159 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
160 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
161 e7e5fa49 2022-12-30 thomas struct gotweb_url summary = {
162 e7e5fa49 2022-12-30 thomas .action = SUMMARY,
163 e7e5fa49 2022-12-30 thomas .index_page = -1,
164 e7e5fa49 2022-12-30 thomas .page = -1,
165 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
166 e7e5fa49 2022-12-30 thomas }, briefs = {
167 e7e5fa49 2022-12-30 thomas .action = BRIEFS,
168 e7e5fa49 2022-12-30 thomas .index_page = -1,
169 e7e5fa49 2022-12-30 thomas .page = -1,
170 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
171 e7e5fa49 2022-12-30 thomas }, commits = {
172 e7e5fa49 2022-12-30 thomas .action = COMMITS,
173 e7e5fa49 2022-12-30 thomas .index_page = -1,
174 e7e5fa49 2022-12-30 thomas .page = -1,
175 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
176 e7e5fa49 2022-12-30 thomas }, tags = {
177 e7e5fa49 2022-12-30 thomas .action = TAGS,
178 e7e5fa49 2022-12-30 thomas .index_page = -1,
179 e7e5fa49 2022-12-30 thomas .page = -1,
180 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
181 e7e5fa49 2022-12-30 thomas }, tree = {
182 e7e5fa49 2022-12-30 thomas .action = TREE,
183 e7e5fa49 2022-12-30 thomas .index_page = -1,
184 e7e5fa49 2022-12-30 thomas .page = -1,
185 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
186 d6795e9f 2022-12-30 thomas }, rss = {
187 d6795e9f 2022-12-30 thomas .action = RSS,
188 d6795e9f 2022-12-30 thomas .index_page = -1,
189 d6795e9f 2022-12-30 thomas .page = -1,
190 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
191 e7e5fa49 2022-12-30 thomas };
192 e7e5fa49 2022-12-30 thomas !}
193 e7e5fa49 2022-12-30 thomas <div class="index_wrapper">
194 e7e5fa49 2022-12-30 thomas <div class="index_project">
195 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
196 e7e5fa49 2022-12-30 thomas </div>
197 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_description }}
198 e7e5fa49 2022-12-30 thomas <div class="index_project_description">
199 e7e5fa49 2022-12-30 thomas {{ repo_dir->description }}
200 e7e5fa49 2022-12-30 thomas </div>
201 e7e5fa49 2022-12-30 thomas {{ end }}
202 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_owner }}
203 e7e5fa49 2022-12-30 thomas <div class="index_project_owner">
204 e7e5fa49 2022-12-30 thomas {{ repo_dir->owner }}
205 e7e5fa49 2022-12-30 thomas </div>
206 e7e5fa49 2022-12-30 thomas {{ end }}
207 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_age }}
208 e7e5fa49 2022-12-30 thomas <div class="index_project_age">
209 e7e5fa49 2022-12-30 thomas {{ repo_dir->age }}
210 e7e5fa49 2022-12-30 thomas </div>
211 e7e5fa49 2022-12-30 thomas {{ end }}
212 e7e5fa49 2022-12-30 thomas <div class="navs_wrapper">
213 e7e5fa49 2022-12-30 thomas <div class="navs">
214 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
215 e7e5fa49 2022-12-30 thomas {{ " | " }}
216 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
217 e7e5fa49 2022-12-30 thomas {{ " | " }}
218 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
219 e7e5fa49 2022-12-30 thomas {{ " | " }}
220 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
221 e7e5fa49 2022-12-30 thomas {{ " | " }}
222 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
223 d6795e9f 2022-12-30 thomas {{ " | " }}
224 d6795e9f 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
225 e7e5fa49 2022-12-30 thomas </div>
226 e7e5fa49 2022-12-30 thomas <div class="dotted_line"></div>
227 e7e5fa49 2022-12-30 thomas </div>
228 e7e5fa49 2022-12-30 thomas </div>
229 e7e5fa49 2022-12-30 thomas {{ end }}
230 e7e5fa49 2022-12-30 thomas
231 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_briefs(struct template *tp) }}
232 e7e5fa49 2022-12-30 thomas {!
233 e7e5fa49 2022-12-30 thomas const struct got_error *error;
234 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
235 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
236 e7e5fa49 2022-12-30 thomas struct transport *t = c->t;
237 e7e5fa49 2022-12-30 thomas struct querystring *qs = c->t->qs;
238 e7e5fa49 2022-12-30 thomas struct repo_commit *rc;
239 e7e5fa49 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
240 e7e5fa49 2022-12-30 thomas struct gotweb_url diff_url, tree_url;
241 e7e5fa49 2022-12-30 thomas char *tmp;
242 e7e5fa49 2022-12-30 thomas
243 e7e5fa49 2022-12-30 thomas diff_url = (struct gotweb_url){
244 e7e5fa49 2022-12-30 thomas .action = DIFF,
245 e7e5fa49 2022-12-30 thomas .index_page = -1,
246 e7e5fa49 2022-12-30 thomas .page = -1,
247 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
248 e7e5fa49 2022-12-30 thomas .headref = qs->headref,
249 e7e5fa49 2022-12-30 thomas };
250 e7e5fa49 2022-12-30 thomas tree_url = (struct gotweb_url){
251 e7e5fa49 2022-12-30 thomas .action = TREE,
252 e7e5fa49 2022-12-30 thomas .index_page = -1,
253 e7e5fa49 2022-12-30 thomas .page = -1,
254 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
255 e7e5fa49 2022-12-30 thomas .headref = qs->headref,
256 e7e5fa49 2022-12-30 thomas };
257 e7e5fa49 2022-12-30 thomas
258 e7e5fa49 2022-12-30 thomas if (qs->action == SUMMARY) {
259 e7e5fa49 2022-12-30 thomas qs->action = BRIEFS;
260 e7e5fa49 2022-12-30 thomas error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
261 e7e5fa49 2022-12-30 thomas } else
262 e7e5fa49 2022-12-30 thomas error = got_get_repo_commits(c, srv->max_commits_display);
263 e7e5fa49 2022-12-30 thomas if (error)
264 e7e5fa49 2022-12-30 thomas return -1;
265 e7e5fa49 2022-12-30 thomas !}
266 e7e5fa49 2022-12-30 thomas <div id="briefs_title_wrapper">
267 e7e5fa49 2022-12-30 thomas <div id="briefs_title">Commit Briefs</div>
268 e7e5fa49 2022-12-30 thomas </div>
269 e7e5fa49 2022-12-30 thomas <div id="briefs_content">
270 e7e5fa49 2022-12-30 thomas {{ tailq-foreach rc &t->repo_commits entry }}
271 e7e5fa49 2022-12-30 thomas {!
272 e7e5fa49 2022-12-30 thomas diff_url.commit = rc->commit_id;
273 e7e5fa49 2022-12-30 thomas tree_url.commit = rc->commit_id;
274 e7e5fa49 2022-12-30 thomas
275 e7e5fa49 2022-12-30 thomas tmp = strchr(rc->author, '<');
276 e7e5fa49 2022-12-30 thomas if (tmp)
277 e7e5fa49 2022-12-30 thomas *tmp = '\0';
278 e7e5fa49 2022-12-30 thomas
279 e7e5fa49 2022-12-30 thomas tmp = strchr(rc->commit_msg, '\n');
280 e7e5fa49 2022-12-30 thomas if (tmp)
281 e7e5fa49 2022-12-30 thomas *tmp = '\0';
282 e7e5fa49 2022-12-30 thomas !}
283 e7e5fa49 2022-12-30 thomas <div class="briefs_age">
284 e7e5fa49 2022-12-30 thomas {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
285 e7e5fa49 2022-12-30 thomas </div>
286 e7e5fa49 2022-12-30 thomas <div class="briefs_author">
287 e7e5fa49 2022-12-30 thomas {{ rc->author }}
288 e7e5fa49 2022-12-30 thomas </div>
289 e7e5fa49 2022-12-30 thomas <div class="briefs_log">
290 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
291 e7e5fa49 2022-12-30 thomas {{ rc->commit_msg }}
292 e7e5fa49 2022-12-30 thomas </a>
293 e7e5fa49 2022-12-30 thomas {{ if rc->refs_str }}
294 e7e5fa49 2022-12-30 thomas {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
295 e7e5fa49 2022-12-30 thomas {{ end }}
296 e7e5fa49 2022-12-30 thomas </a>
297 e7e5fa49 2022-12-30 thomas </div>
298 e7e5fa49 2022-12-30 thomas <div class="navs_wrapper">
299 e7e5fa49 2022-12-30 thomas <div class="navs">
300 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
301 e7e5fa49 2022-12-30 thomas {{ " | " }}
302 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
303 e7e5fa49 2022-12-30 thomas </div>
304 e7e5fa49 2022-12-30 thomas </div>
305 e7e5fa49 2022-12-30 thomas <div class="dotted_line"></div>
306 e7e5fa49 2022-12-30 thomas {{ end }}
307 e7e5fa49 2022-12-30 thomas {{ if t->next_id || t->prev_id }}
308 2f4f0731 2022-12-30 thomas {{ render gotweb_render_navs(tp) }}
309 e7e5fa49 2022-12-30 thomas {{ end }}
310 2f4f0731 2022-12-30 thomas </div>
311 2f4f0731 2022-12-30 thomas {{ end }}
312 2f4f0731 2022-12-30 thomas
313 2f4f0731 2022-12-30 thomas {{ define gotweb_render_navs(struct template *tp) }}
314 2f4f0731 2022-12-30 thomas {!
315 2f4f0731 2022-12-30 thomas struct request *c = tp->tp_arg;
316 2f4f0731 2022-12-30 thomas struct transport *t = c->t;
317 2f4f0731 2022-12-30 thomas struct gotweb_url prev, next;
318 2f4f0731 2022-12-30 thomas int have_prev, have_next;
319 2f4f0731 2022-12-30 thomas
320 2f4f0731 2022-12-30 thomas gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
321 2f4f0731 2022-12-30 thomas !}
322 2f4f0731 2022-12-30 thomas <div id="np_wrapper">
323 2f4f0731 2022-12-30 thomas <div id="nav_prev">
324 2f4f0731 2022-12-30 thomas {{ if have_prev }}
325 2f4f0731 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &prev) }}">
326 2f4f0731 2022-12-30 thomas Previous
327 2f4f0731 2022-12-30 thomas </a>
328 2f4f0731 2022-12-30 thomas {{ end }}
329 2f4f0731 2022-12-30 thomas </div>
330 2f4f0731 2022-12-30 thomas <div id="nav_next">
331 2f4f0731 2022-12-30 thomas {{ if have_next }}
332 2f4f0731 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &next) }}">
333 2f4f0731 2022-12-30 thomas Next
334 2f4f0731 2022-12-30 thomas </a>
335 2f4f0731 2022-12-30 thomas {{ end }}
336 2f4f0731 2022-12-30 thomas </div>
337 e7e5fa49 2022-12-30 thomas </div>
338 2f4f0731 2022-12-30 thomas {{ finally }}
339 2f4f0731 2022-12-30 thomas {!
340 2f4f0731 2022-12-30 thomas free(t->next_id);
341 2f4f0731 2022-12-30 thomas t->next_id = NULL;
342 2f4f0731 2022-12-30 thomas free(t->prev_id);
343 2f4f0731 2022-12-30 thomas t->prev_id = NULL;
344 2f4f0731 2022-12-30 thomas !}
345 e7e5fa49 2022-12-30 thomas {{ end }}
346 7ade8b27 2022-12-30 thomas
347 7ade8b27 2022-12-30 thomas {{ define gotweb_render_commits(struct template *tp) }}
348 7ade8b27 2022-12-30 thomas {!
349 7ade8b27 2022-12-30 thomas struct request *c = tp->tp_arg;
350 7ade8b27 2022-12-30 thomas struct transport *t = c->t;
351 7ade8b27 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
352 7ade8b27 2022-12-30 thomas struct repo_commit *rc;
353 7ade8b27 2022-12-30 thomas struct gotweb_url diff, tree;
354 7ade8b27 2022-12-30 thomas
355 7ade8b27 2022-12-30 thomas diff = (struct gotweb_url){
356 7ade8b27 2022-12-30 thomas .action = DIFF,
357 7ade8b27 2022-12-30 thomas .index_page = -1,
358 7ade8b27 2022-12-30 thomas .page = -1,
359 7ade8b27 2022-12-30 thomas .path = repo_dir->name,
360 7ade8b27 2022-12-30 thomas };
361 7ade8b27 2022-12-30 thomas tree = (struct gotweb_url){
362 7ade8b27 2022-12-30 thomas .action = TREE,
363 7ade8b27 2022-12-30 thomas .index_page = -1,
364 7ade8b27 2022-12-30 thomas .page = -1,
365 7ade8b27 2022-12-30 thomas .path = repo_dir->name,
366 7ade8b27 2022-12-30 thomas };
367 7ade8b27 2022-12-30 thomas !}
368 7ade8b27 2022-12-30 thomas <div class="commits_title_wrapper">
369 7ade8b27 2022-12-30 thomas <div class="commits_title">Commits</div>
370 7ade8b27 2022-12-30 thomas </div>
371 7ade8b27 2022-12-30 thomas <div class="commits_content">
372 7ade8b27 2022-12-30 thomas {{ tailq-foreach rc &t->repo_commits entry }}
373 7ade8b27 2022-12-30 thomas {!
374 7ade8b27 2022-12-30 thomas diff.commit = rc->commit_id;
375 7ade8b27 2022-12-30 thomas tree.commit = rc->commit_id;
376 7ade8b27 2022-12-30 thomas !}
377 7ade8b27 2022-12-30 thomas <div class="commits_header_wrapper">
378 7ade8b27 2022-12-30 thomas <div class="commits_header">
379 7ade8b27 2022-12-30 thomas <div class="header_commit_title">Commit:</div>
380 7ade8b27 2022-12-30 thomas <div class="header_commit">{{ rc->commit_id }}</div>
381 7ade8b27 2022-12-30 thomas <div class="header_author_title">Author:</div>
382 7ade8b27 2022-12-30 thomas <div class="header_author">{{ rc->author }}</div>
383 7ade8b27 2022-12-30 thomas <div class="header_age_title">Date:</div>
384 7ade8b27 2022-12-30 thomas <div class="header_age">
385 7ade8b27 2022-12-30 thomas {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
386 7ade8b27 2022-12-30 thomas </div>
387 7ade8b27 2022-12-30 thomas </div>
388 7ade8b27 2022-12-30 thomas </div>
389 bbf94fd6 2023-01-02 thomas <div class="dotted_line"></div>
390 bbf94fd6 2023-01-02 thomas <div class="commit">
391 bbf94fd6 2023-01-02 thomas {{ "\n" }}
392 bbf94fd6 2023-01-02 thomas {{ rc->commit_msg }}
393 bbf94fd6 2023-01-02 thomas </div>
394 7ade8b27 2022-12-30 thomas <div class="navs_wrapper">
395 7ade8b27 2022-12-30 thomas <div class="navs">
396 7ade8b27 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
397 7ade8b27 2022-12-30 thomas {{ " | " }}
398 7ade8b27 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
399 7ade8b27 2022-12-30 thomas </div>
400 7ade8b27 2022-12-30 thomas </div>
401 7ade8b27 2022-12-30 thomas <div class="dotted_line"></div>
402 7ade8b27 2022-12-30 thomas {{ end }}
403 7ade8b27 2022-12-30 thomas {{ if t->next_id || t->prev_id }}
404 7ade8b27 2022-12-30 thomas {{ render gotweb_render_navs(tp) }}
405 7ade8b27 2022-12-30 thomas {{ end }}
406 7ade8b27 2022-12-30 thomas </div>
407 d6795e9f 2022-12-30 thomas {{ end }}
408 d6795e9f 2022-12-30 thomas
409 d6795e9f 2022-12-30 thomas {{ define gotweb_render_rss(struct template *tp) }}
410 d6795e9f 2022-12-30 thomas {!
411 d6795e9f 2022-12-30 thomas struct request *c = tp->tp_arg;
412 d6795e9f 2022-12-30 thomas struct server *srv = c->srv;
413 d6795e9f 2022-12-30 thomas struct transport *t = c->t;
414 d6795e9f 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
415 d6795e9f 2022-12-30 thomas struct repo_tag *rt;
416 d6795e9f 2022-12-30 thomas struct gotweb_url summary = {
417 d6795e9f 2022-12-30 thomas .action = SUMMARY,
418 d6795e9f 2022-12-30 thomas .index_page = -1,
419 d6795e9f 2022-12-30 thomas .page = -1,
420 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
421 d6795e9f 2022-12-30 thomas };
422 d6795e9f 2022-12-30 thomas !}
423 d6795e9f 2022-12-30 thomas <?xml version="1.0" encoding="UTF-8"?>
424 d6795e9f 2022-12-30 thomas <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
425 d6795e9f 2022-12-30 thomas <channel>
426 d6795e9f 2022-12-30 thomas <title>Tags of {{ repo_dir->name }}</title>
427 d6795e9f 2022-12-30 thomas <link>
428 d6795e9f 2022-12-30 thomas <![CDATA[
429 d6795e9f 2022-12-30 thomas {{ render gotweb_render_absolute_url(c, &summary) }}
430 d6795e9f 2022-12-30 thomas ]]>
431 d6795e9f 2022-12-30 thomas </link>
432 d6795e9f 2022-12-30 thomas {{ if srv->show_repo_description }}
433 d6795e9f 2022-12-30 thomas <description>{{ repo_dir->description }}</description>
434 d6795e9f 2022-12-30 thomas {{ end }}
435 d6795e9f 2022-12-30 thomas {{ tailq-foreach rt &t->repo_tags entry }}
436 d6795e9f 2022-12-30 thomas {{ render rss_tag_item(tp, rt) }}
437 d6795e9f 2022-12-30 thomas {{ end }}
438 d6795e9f 2022-12-30 thomas </channel>
439 d6795e9f 2022-12-30 thomas </rss>
440 d6795e9f 2022-12-30 thomas {{ end }}
441 d6795e9f 2022-12-30 thomas
442 d6795e9f 2022-12-30 thomas {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
443 d6795e9f 2022-12-30 thomas {!
444 d6795e9f 2022-12-30 thomas struct request *c = tp->tp_arg;
445 d6795e9f 2022-12-30 thomas struct transport *t = c->t;
446 d6795e9f 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
447 d6795e9f 2022-12-30 thomas char *tag_name = rt->tag_name;
448 d6795e9f 2022-12-30 thomas struct gotweb_url tag = {
449 d6795e9f 2022-12-30 thomas .action = TAG,
450 d6795e9f 2022-12-30 thomas .index_page = -1,
451 d6795e9f 2022-12-30 thomas .page = -1,
452 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
453 d6795e9f 2022-12-30 thomas .commit = rt->commit_id,
454 d6795e9f 2022-12-30 thomas };
455 d6795e9f 2022-12-30 thomas
456 d6795e9f 2022-12-30 thomas if (strncmp(tag_name, "refs/tags/", 10) == 0)
457 d6795e9f 2022-12-30 thomas tag_name += 10;
458 d6795e9f 2022-12-30 thomas !}
459 d6795e9f 2022-12-30 thomas <item>
460 d6795e9f 2022-12-30 thomas <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
461 d6795e9f 2022-12-30 thomas <link>
462 d6795e9f 2022-12-30 thomas <![CDATA[
463 d6795e9f 2022-12-30 thomas {{ render gotweb_render_absolute_url(c, &tag) }}
464 d6795e9f 2022-12-30 thomas ]]>
465 d6795e9f 2022-12-30 thomas </link>
466 d6795e9f 2022-12-30 thomas <description>
467 d6795e9f 2022-12-30 thomas <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
468 d6795e9f 2022-12-30 thomas </description>
469 d6795e9f 2022-12-30 thomas {{ render rss_author(tp, rt->tagger) }}
470 d6795e9f 2022-12-30 thomas <guid isPermaLink="false">{{ rt->commit_id }}</guid>
471 d6795e9f 2022-12-30 thomas <pubDate>
472 d6795e9f 2022-12-30 thomas {{ render gotweb_render_age(tp, rt->tagger_time, TM_RFC822) }}
473 d6795e9f 2022-12-30 thomas </pubDate>
474 d6795e9f 2022-12-30 thomas </item>
475 7ade8b27 2022-12-30 thomas {{ end }}
476 d6795e9f 2022-12-30 thomas
477 d6795e9f 2022-12-30 thomas {{ define rss_author(struct template *tp, char *author) }}
478 d6795e9f 2022-12-30 thomas {!
479 d6795e9f 2022-12-30 thomas char *t, *mail;
480 d6795e9f 2022-12-30 thomas
481 d6795e9f 2022-12-30 thomas /* what to do if the author name contains a paren? */
482 d6795e9f 2022-12-30 thomas if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
483 d6795e9f 2022-12-30 thomas return 0;
484 d6795e9f 2022-12-30 thomas
485 d6795e9f 2022-12-30 thomas t = strchr(author, '<');
486 d6795e9f 2022-12-30 thomas if (t == NULL)
487 d6795e9f 2022-12-30 thomas return 0;
488 d6795e9f 2022-12-30 thomas *t = '\0';
489 d6795e9f 2022-12-30 thomas mail = t+1;
490 d6795e9f 2022-12-30 thomas
491 d6795e9f 2022-12-30 thomas while (isspace((unsigned char)*--t))
492 d6795e9f 2022-12-30 thomas *t = '\0';
493 d6795e9f 2022-12-30 thomas
494 d6795e9f 2022-12-30 thomas t = strchr(mail, '>');
495 d6795e9f 2022-12-30 thomas if (t == NULL)
496 d6795e9f 2022-12-30 thomas return 0;
497 d6795e9f 2022-12-30 thomas *t = '\0';
498 d6795e9f 2022-12-30 thomas !}
499 d6795e9f 2022-12-30 thomas <author>
500 d6795e9f 2022-12-30 thomas {{ mail }} {{" "}} ({{ author }})
501 d6795e9f 2022-12-30 thomas </author>
502 d6795e9f 2022-12-30 thomas {{ end }}