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 b82440e1 2023-01-06 thomas static int gotweb_render_blob_line(struct template *, const char *, size_t);
35 b82440e1 2023-01-06 thomas
36 d6795e9f 2022-12-30 thomas static inline int rss_tag_item(struct template *, struct repo_tag *);
37 d6795e9f 2022-12-30 thomas static inline int rss_author(struct template *, char *);
38 d6795e9f 2022-12-30 thomas
39 e7e5fa49 2022-12-30 thomas static int
40 e7e5fa49 2022-12-30 thomas gotweb_render_age(struct template *tp, time_t time, int ref_tm)
41 e7e5fa49 2022-12-30 thomas {
42 e7e5fa49 2022-12-30 thomas const struct got_error *err;
43 e7e5fa49 2022-12-30 thomas char *age;
44 e7e5fa49 2022-12-30 thomas int r;
45 e7e5fa49 2022-12-30 thomas
46 e7e5fa49 2022-12-30 thomas err = gotweb_get_time_str(&age, time, ref_tm);
47 e7e5fa49 2022-12-30 thomas if (err)
48 e7e5fa49 2022-12-30 thomas return 0;
49 e7e5fa49 2022-12-30 thomas r = tp->tp_puts(tp, age);
50 e7e5fa49 2022-12-30 thomas free(age);
51 e7e5fa49 2022-12-30 thomas return r;
52 e7e5fa49 2022-12-30 thomas }
53 e7e5fa49 2022-12-30 thomas
54 e7e5fa49 2022-12-30 thomas !}
55 e7e5fa49 2022-12-30 thomas
56 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_header(struct template *tp) }}
57 e7e5fa49 2022-12-30 thomas {!
58 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
59 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
60 e7e5fa49 2022-12-30 thomas struct querystring *qs = c->t->qs;
61 e7e5fa49 2022-12-30 thomas struct gotweb_url u_path;
62 3191e256 2022-12-30 thomas const char *prfx = c->document_uri;
63 e7e5fa49 2022-12-30 thomas const char *css = srv->custom_css;
64 e7e5fa49 2022-12-30 thomas
65 e7e5fa49 2022-12-30 thomas memset(&u_path, 0, sizeof(u_path));
66 e7e5fa49 2022-12-30 thomas u_path.index_page = -1;
67 e7e5fa49 2022-12-30 thomas u_path.page = -1;
68 e7e5fa49 2022-12-30 thomas u_path.action = SUMMARY;
69 e7e5fa49 2022-12-30 thomas !}
70 e7e5fa49 2022-12-30 thomas <!doctype html>
71 e7e5fa49 2022-12-30 thomas <html>
72 e7e5fa49 2022-12-30 thomas <head>
73 e7e5fa49 2022-12-30 thomas <meta charset="utf-8" />
74 e7e5fa49 2022-12-30 thomas <title>{{ srv->site_name }}</title>
75 e7e5fa49 2022-12-30 thomas <meta name="viewport" content="initial-scale=.75" />
76 e7e5fa49 2022-12-30 thomas <meta name="msapplication-TileColor" content="#da532c" />
77 e7e5fa49 2022-12-30 thomas <meta name="theme-color" content="#ffffff"/>
78 e7e5fa49 2022-12-30 thomas <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
79 e7e5fa49 2022-12-30 thomas <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
80 e7e5fa49 2022-12-30 thomas <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
81 e7e5fa49 2022-12-30 thomas <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
82 e7e5fa49 2022-12-30 thomas <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
83 e7e5fa49 2022-12-30 thomas <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
84 e7e5fa49 2022-12-30 thomas </head>
85 e7e5fa49 2022-12-30 thomas <body>
86 e7e5fa49 2022-12-30 thomas <div id="gw_body">
87 e7e5fa49 2022-12-30 thomas <div id="header">
88 e7e5fa49 2022-12-30 thomas <div id="got_link">
89 e7e5fa49 2022-12-30 thomas <a href="{{ srv->logo_url }}" target="_blank">
90 e7e5fa49 2022-12-30 thomas <img src="{{ prfx }}{{ srv->logo }}" />
91 e7e5fa49 2022-12-30 thomas </a>
92 e7e5fa49 2022-12-30 thomas </div>
93 e7e5fa49 2022-12-30 thomas </div>
94 e7e5fa49 2022-12-30 thomas <div id="site_path">
95 e7e5fa49 2022-12-30 thomas <div id="site_link">
96 e7e5fa49 2022-12-30 thomas <a href="?index_page={{ printf "%d", qs->index_page }}">
97 e7e5fa49 2022-12-30 thomas {{ srv->site_link }}
98 e7e5fa49 2022-12-30 thomas </a>
99 e7e5fa49 2022-12-30 thomas {{ if qs->path }}
100 e7e5fa49 2022-12-30 thomas {! u_path.path = qs->path; !}
101 e7e5fa49 2022-12-30 thomas {{ " / " }}
102 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
103 e7e5fa49 2022-12-30 thomas {{ qs->path }}
104 e7e5fa49 2022-12-30 thomas </a>
105 e7e5fa49 2022-12-30 thomas {{ end }}
106 e7e5fa49 2022-12-30 thomas {{ if qs->action != INDEX }}
107 e7e5fa49 2022-12-30 thomas {{ " / " }}{{ gotweb_action_name(qs->action) }}
108 e7e5fa49 2022-12-30 thomas {{ end }}
109 e7e5fa49 2022-12-30 thomas </div>
110 e7e5fa49 2022-12-30 thomas </div>
111 e7e5fa49 2022-12-30 thomas <div id="content">
112 e7e5fa49 2022-12-30 thomas {{ end }}
113 e7e5fa49 2022-12-30 thomas
114 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_footer(struct template *tp) }}
115 e7e5fa49 2022-12-30 thomas {!
116 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
117 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
118 e7e5fa49 2022-12-30 thomas !}
119 e7e5fa49 2022-12-30 thomas <div id="site_owner_wrapper">
120 e7e5fa49 2022-12-30 thomas <div id="site_owner">
121 e7e5fa49 2022-12-30 thomas {{ if srv->show_site_owner }}
122 e7e5fa49 2022-12-30 thomas {{ srv->site_owner }}
123 e7e5fa49 2022-12-30 thomas {{ end }}
124 e7e5fa49 2022-12-30 thomas </div>
125 e7e5fa49 2022-12-30 thomas </div>
126 e7e5fa49 2022-12-30 thomas </div>
127 e7e5fa49 2022-12-30 thomas </div>
128 e7e5fa49 2022-12-30 thomas </body>
129 e7e5fa49 2022-12-30 thomas </html>
130 e7e5fa49 2022-12-30 thomas {{ end }}
131 e7e5fa49 2022-12-30 thomas
132 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
133 e7e5fa49 2022-12-30 thomas {!
134 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
135 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
136 e7e5fa49 2022-12-30 thomas !}
137 e7e5fa49 2022-12-30 thomas <div id="index_header">
138 e7e5fa49 2022-12-30 thomas <div id="index_header_project">
139 e7e5fa49 2022-12-30 thomas Project
140 e7e5fa49 2022-12-30 thomas </div>
141 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_description }}
142 e7e5fa49 2022-12-30 thomas <div id="index_header_description">
143 e7e5fa49 2022-12-30 thomas Description
144 e7e5fa49 2022-12-30 thomas </div>
145 e7e5fa49 2022-12-30 thomas {{ end }}
146 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_owner }}
147 e7e5fa49 2022-12-30 thomas <div id="index_header_owner">
148 e7e5fa49 2022-12-30 thomas Owner
149 e7e5fa49 2022-12-30 thomas </div>
150 e7e5fa49 2022-12-30 thomas {{ end }}
151 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_age }}
152 e7e5fa49 2022-12-30 thomas <div id="index_header_age">
153 e7e5fa49 2022-12-30 thomas Last Change
154 e7e5fa49 2022-12-30 thomas </div>
155 e7e5fa49 2022-12-30 thomas {{ end }}
156 e7e5fa49 2022-12-30 thomas </div>
157 e7e5fa49 2022-12-30 thomas {{ end }}
158 e7e5fa49 2022-12-30 thomas
159 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
160 e7e5fa49 2022-12-30 thomas {!
161 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
162 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
163 e7e5fa49 2022-12-30 thomas struct gotweb_url summary = {
164 e7e5fa49 2022-12-30 thomas .action = SUMMARY,
165 e7e5fa49 2022-12-30 thomas .index_page = -1,
166 e7e5fa49 2022-12-30 thomas .page = -1,
167 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
168 e7e5fa49 2022-12-30 thomas }, briefs = {
169 e7e5fa49 2022-12-30 thomas .action = BRIEFS,
170 e7e5fa49 2022-12-30 thomas .index_page = -1,
171 e7e5fa49 2022-12-30 thomas .page = -1,
172 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
173 e7e5fa49 2022-12-30 thomas }, commits = {
174 e7e5fa49 2022-12-30 thomas .action = COMMITS,
175 e7e5fa49 2022-12-30 thomas .index_page = -1,
176 e7e5fa49 2022-12-30 thomas .page = -1,
177 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
178 e7e5fa49 2022-12-30 thomas }, tags = {
179 e7e5fa49 2022-12-30 thomas .action = TAGS,
180 e7e5fa49 2022-12-30 thomas .index_page = -1,
181 e7e5fa49 2022-12-30 thomas .page = -1,
182 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
183 e7e5fa49 2022-12-30 thomas }, tree = {
184 e7e5fa49 2022-12-30 thomas .action = TREE,
185 e7e5fa49 2022-12-30 thomas .index_page = -1,
186 e7e5fa49 2022-12-30 thomas .page = -1,
187 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
188 d6795e9f 2022-12-30 thomas }, rss = {
189 d6795e9f 2022-12-30 thomas .action = RSS,
190 d6795e9f 2022-12-30 thomas .index_page = -1,
191 d6795e9f 2022-12-30 thomas .page = -1,
192 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
193 e7e5fa49 2022-12-30 thomas };
194 e7e5fa49 2022-12-30 thomas !}
195 e7e5fa49 2022-12-30 thomas <div class="index_wrapper">
196 e7e5fa49 2022-12-30 thomas <div class="index_project">
197 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
198 e7e5fa49 2022-12-30 thomas </div>
199 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_description }}
200 e7e5fa49 2022-12-30 thomas <div class="index_project_description">
201 e7e5fa49 2022-12-30 thomas {{ repo_dir->description }}
202 e7e5fa49 2022-12-30 thomas </div>
203 e7e5fa49 2022-12-30 thomas {{ end }}
204 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_owner }}
205 e7e5fa49 2022-12-30 thomas <div class="index_project_owner">
206 e7e5fa49 2022-12-30 thomas {{ repo_dir->owner }}
207 e7e5fa49 2022-12-30 thomas </div>
208 e7e5fa49 2022-12-30 thomas {{ end }}
209 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_age }}
210 e7e5fa49 2022-12-30 thomas <div class="index_project_age">
211 e7e5fa49 2022-12-30 thomas {{ repo_dir->age }}
212 e7e5fa49 2022-12-30 thomas </div>
213 e7e5fa49 2022-12-30 thomas {{ end }}
214 e7e5fa49 2022-12-30 thomas <div class="navs_wrapper">
215 e7e5fa49 2022-12-30 thomas <div class="navs">
216 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
217 e7e5fa49 2022-12-30 thomas {{ " | " }}
218 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
219 e7e5fa49 2022-12-30 thomas {{ " | " }}
220 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
221 e7e5fa49 2022-12-30 thomas {{ " | " }}
222 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
223 e7e5fa49 2022-12-30 thomas {{ " | " }}
224 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
225 d6795e9f 2022-12-30 thomas {{ " | " }}
226 d6795e9f 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
227 e7e5fa49 2022-12-30 thomas </div>
228 e7e5fa49 2022-12-30 thomas <div class="dotted_line"></div>
229 e7e5fa49 2022-12-30 thomas </div>
230 e7e5fa49 2022-12-30 thomas </div>
231 e7e5fa49 2022-12-30 thomas {{ end }}
232 e7e5fa49 2022-12-30 thomas
233 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_briefs(struct template *tp) }}
234 e7e5fa49 2022-12-30 thomas {!
235 e7e5fa49 2022-12-30 thomas const struct got_error *error;
236 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
237 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
238 e7e5fa49 2022-12-30 thomas struct transport *t = c->t;
239 e7e5fa49 2022-12-30 thomas struct querystring *qs = c->t->qs;
240 e7e5fa49 2022-12-30 thomas struct repo_commit *rc;
241 e7e5fa49 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
242 e7e5fa49 2022-12-30 thomas struct gotweb_url diff_url, tree_url;
243 e7e5fa49 2022-12-30 thomas char *tmp;
244 e7e5fa49 2022-12-30 thomas
245 e7e5fa49 2022-12-30 thomas diff_url = (struct gotweb_url){
246 e7e5fa49 2022-12-30 thomas .action = DIFF,
247 e7e5fa49 2022-12-30 thomas .index_page = -1,
248 e7e5fa49 2022-12-30 thomas .page = -1,
249 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
250 e7e5fa49 2022-12-30 thomas .headref = qs->headref,
251 e7e5fa49 2022-12-30 thomas };
252 e7e5fa49 2022-12-30 thomas tree_url = (struct gotweb_url){
253 e7e5fa49 2022-12-30 thomas .action = TREE,
254 e7e5fa49 2022-12-30 thomas .index_page = -1,
255 e7e5fa49 2022-12-30 thomas .page = -1,
256 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
257 e7e5fa49 2022-12-30 thomas .headref = qs->headref,
258 e7e5fa49 2022-12-30 thomas };
259 e7e5fa49 2022-12-30 thomas
260 e7e5fa49 2022-12-30 thomas if (qs->action == SUMMARY) {
261 e7e5fa49 2022-12-30 thomas qs->action = BRIEFS;
262 e7e5fa49 2022-12-30 thomas error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
263 e7e5fa49 2022-12-30 thomas } else
264 e7e5fa49 2022-12-30 thomas error = got_get_repo_commits(c, srv->max_commits_display);
265 e7e5fa49 2022-12-30 thomas if (error)
266 e7e5fa49 2022-12-30 thomas return -1;
267 e7e5fa49 2022-12-30 thomas !}
268 e7e5fa49 2022-12-30 thomas <div id="briefs_title_wrapper">
269 e7e5fa49 2022-12-30 thomas <div id="briefs_title">Commit Briefs</div>
270 e7e5fa49 2022-12-30 thomas </div>
271 e7e5fa49 2022-12-30 thomas <div id="briefs_content">
272 e7e5fa49 2022-12-30 thomas {{ tailq-foreach rc &t->repo_commits entry }}
273 e7e5fa49 2022-12-30 thomas {!
274 e7e5fa49 2022-12-30 thomas diff_url.commit = rc->commit_id;
275 e7e5fa49 2022-12-30 thomas tree_url.commit = rc->commit_id;
276 e7e5fa49 2022-12-30 thomas
277 e7e5fa49 2022-12-30 thomas tmp = strchr(rc->author, '<');
278 e7e5fa49 2022-12-30 thomas if (tmp)
279 e7e5fa49 2022-12-30 thomas *tmp = '\0';
280 e7e5fa49 2022-12-30 thomas
281 e7e5fa49 2022-12-30 thomas tmp = strchr(rc->commit_msg, '\n');
282 e7e5fa49 2022-12-30 thomas if (tmp)
283 e7e5fa49 2022-12-30 thomas *tmp = '\0';
284 e7e5fa49 2022-12-30 thomas !}
285 e7e5fa49 2022-12-30 thomas <div class="briefs_age">
286 e7e5fa49 2022-12-30 thomas {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
287 e7e5fa49 2022-12-30 thomas </div>
288 e7e5fa49 2022-12-30 thomas <div class="briefs_author">
289 e7e5fa49 2022-12-30 thomas {{ rc->author }}
290 e7e5fa49 2022-12-30 thomas </div>
291 e7e5fa49 2022-12-30 thomas <div class="briefs_log">
292 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
293 e7e5fa49 2022-12-30 thomas {{ rc->commit_msg }}
294 e7e5fa49 2022-12-30 thomas </a>
295 e7e5fa49 2022-12-30 thomas {{ if rc->refs_str }}
296 e7e5fa49 2022-12-30 thomas {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
297 e7e5fa49 2022-12-30 thomas {{ end }}
298 e7e5fa49 2022-12-30 thomas </a>
299 e7e5fa49 2022-12-30 thomas </div>
300 e7e5fa49 2022-12-30 thomas <div class="navs_wrapper">
301 e7e5fa49 2022-12-30 thomas <div class="navs">
302 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
303 e7e5fa49 2022-12-30 thomas {{ " | " }}
304 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
305 e7e5fa49 2022-12-30 thomas </div>
306 e7e5fa49 2022-12-30 thomas </div>
307 e7e5fa49 2022-12-30 thomas <div class="dotted_line"></div>
308 e7e5fa49 2022-12-30 thomas {{ end }}
309 e7e5fa49 2022-12-30 thomas {{ if t->next_id || t->prev_id }}
310 2f4f0731 2022-12-30 thomas {{ render gotweb_render_navs(tp) }}
311 e7e5fa49 2022-12-30 thomas {{ end }}
312 2f4f0731 2022-12-30 thomas </div>
313 2f4f0731 2022-12-30 thomas {{ end }}
314 2f4f0731 2022-12-30 thomas
315 2f4f0731 2022-12-30 thomas {{ define gotweb_render_navs(struct template *tp) }}
316 2f4f0731 2022-12-30 thomas {!
317 2f4f0731 2022-12-30 thomas struct request *c = tp->tp_arg;
318 2f4f0731 2022-12-30 thomas struct transport *t = c->t;
319 2f4f0731 2022-12-30 thomas struct gotweb_url prev, next;
320 2f4f0731 2022-12-30 thomas int have_prev, have_next;
321 2f4f0731 2022-12-30 thomas
322 2f4f0731 2022-12-30 thomas gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
323 2f4f0731 2022-12-30 thomas !}
324 2f4f0731 2022-12-30 thomas <div id="np_wrapper">
325 2f4f0731 2022-12-30 thomas <div id="nav_prev">
326 2f4f0731 2022-12-30 thomas {{ if have_prev }}
327 2f4f0731 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &prev) }}">
328 2f4f0731 2022-12-30 thomas Previous
329 2f4f0731 2022-12-30 thomas </a>
330 2f4f0731 2022-12-30 thomas {{ end }}
331 2f4f0731 2022-12-30 thomas </div>
332 2f4f0731 2022-12-30 thomas <div id="nav_next">
333 2f4f0731 2022-12-30 thomas {{ if have_next }}
334 2f4f0731 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &next) }}">
335 2f4f0731 2022-12-30 thomas Next
336 2f4f0731 2022-12-30 thomas </a>
337 2f4f0731 2022-12-30 thomas {{ end }}
338 2f4f0731 2022-12-30 thomas </div>
339 e7e5fa49 2022-12-30 thomas </div>
340 2f4f0731 2022-12-30 thomas {{ finally }}
341 2f4f0731 2022-12-30 thomas {!
342 2f4f0731 2022-12-30 thomas free(t->next_id);
343 2f4f0731 2022-12-30 thomas t->next_id = NULL;
344 2f4f0731 2022-12-30 thomas free(t->prev_id);
345 2f4f0731 2022-12-30 thomas t->prev_id = NULL;
346 2f4f0731 2022-12-30 thomas !}
347 e7e5fa49 2022-12-30 thomas {{ end }}
348 7ade8b27 2022-12-30 thomas
349 7ade8b27 2022-12-30 thomas {{ define gotweb_render_commits(struct template *tp) }}
350 7ade8b27 2022-12-30 thomas {!
351 7ade8b27 2022-12-30 thomas struct request *c = tp->tp_arg;
352 7ade8b27 2022-12-30 thomas struct transport *t = c->t;
353 7ade8b27 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
354 7ade8b27 2022-12-30 thomas struct repo_commit *rc;
355 7ade8b27 2022-12-30 thomas struct gotweb_url diff, tree;
356 7ade8b27 2022-12-30 thomas
357 7ade8b27 2022-12-30 thomas diff = (struct gotweb_url){
358 7ade8b27 2022-12-30 thomas .action = DIFF,
359 7ade8b27 2022-12-30 thomas .index_page = -1,
360 7ade8b27 2022-12-30 thomas .page = -1,
361 7ade8b27 2022-12-30 thomas .path = repo_dir->name,
362 7ade8b27 2022-12-30 thomas };
363 7ade8b27 2022-12-30 thomas tree = (struct gotweb_url){
364 7ade8b27 2022-12-30 thomas .action = TREE,
365 7ade8b27 2022-12-30 thomas .index_page = -1,
366 7ade8b27 2022-12-30 thomas .page = -1,
367 7ade8b27 2022-12-30 thomas .path = repo_dir->name,
368 7ade8b27 2022-12-30 thomas };
369 7ade8b27 2022-12-30 thomas !}
370 7ade8b27 2022-12-30 thomas <div class="commits_title_wrapper">
371 7ade8b27 2022-12-30 thomas <div class="commits_title">Commits</div>
372 7ade8b27 2022-12-30 thomas </div>
373 7ade8b27 2022-12-30 thomas <div class="commits_content">
374 7ade8b27 2022-12-30 thomas {{ tailq-foreach rc &t->repo_commits entry }}
375 7ade8b27 2022-12-30 thomas {!
376 7ade8b27 2022-12-30 thomas diff.commit = rc->commit_id;
377 7ade8b27 2022-12-30 thomas tree.commit = rc->commit_id;
378 7ade8b27 2022-12-30 thomas !}
379 7ade8b27 2022-12-30 thomas <div class="commits_header_wrapper">
380 7ade8b27 2022-12-30 thomas <div class="commits_header">
381 7ade8b27 2022-12-30 thomas <div class="header_commit_title">Commit:</div>
382 7ade8b27 2022-12-30 thomas <div class="header_commit">{{ rc->commit_id }}</div>
383 7ade8b27 2022-12-30 thomas <div class="header_author_title">Author:</div>
384 7ade8b27 2022-12-30 thomas <div class="header_author">{{ rc->author }}</div>
385 7ade8b27 2022-12-30 thomas <div class="header_age_title">Date:</div>
386 7ade8b27 2022-12-30 thomas <div class="header_age">
387 7ade8b27 2022-12-30 thomas {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
388 7ade8b27 2022-12-30 thomas </div>
389 7ade8b27 2022-12-30 thomas </div>
390 7ade8b27 2022-12-30 thomas </div>
391 bbf94fd6 2023-01-02 thomas <div class="dotted_line"></div>
392 bbf94fd6 2023-01-02 thomas <div class="commit">
393 bbf94fd6 2023-01-02 thomas {{ "\n" }}
394 bbf94fd6 2023-01-02 thomas {{ rc->commit_msg }}
395 bbf94fd6 2023-01-02 thomas </div>
396 7ade8b27 2022-12-30 thomas <div class="navs_wrapper">
397 7ade8b27 2022-12-30 thomas <div class="navs">
398 7ade8b27 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
399 7ade8b27 2022-12-30 thomas {{ " | " }}
400 7ade8b27 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
401 7ade8b27 2022-12-30 thomas </div>
402 7ade8b27 2022-12-30 thomas </div>
403 7ade8b27 2022-12-30 thomas <div class="dotted_line"></div>
404 7ade8b27 2022-12-30 thomas {{ end }}
405 7ade8b27 2022-12-30 thomas {{ if t->next_id || t->prev_id }}
406 7ade8b27 2022-12-30 thomas {{ render gotweb_render_navs(tp) }}
407 7ade8b27 2022-12-30 thomas {{ end }}
408 b82440e1 2023-01-06 thomas </div>
409 b82440e1 2023-01-06 thomas {{ end }}
410 b82440e1 2023-01-06 thomas
411 b82440e1 2023-01-06 thomas {{ define gotweb_render_blob(struct template *tp,
412 b82440e1 2023-01-06 thomas struct got_blob_object *blob) }}
413 b82440e1 2023-01-06 thomas {!
414 b82440e1 2023-01-06 thomas struct request *c = tp->tp_arg;
415 b82440e1 2023-01-06 thomas struct transport *t = c->t;
416 b82440e1 2023-01-06 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
417 b82440e1 2023-01-06 thomas !}
418 b82440e1 2023-01-06 thomas <div id="blob_title_wrapper">
419 b82440e1 2023-01-06 thomas <div id="blob_title">Blob</div>
420 b82440e1 2023-01-06 thomas </div>
421 b82440e1 2023-01-06 thomas <div id="blob_content">
422 b82440e1 2023-01-06 thomas <div id="blob_header_wrapper">
423 b82440e1 2023-01-06 thomas <div id="blob_header">
424 b82440e1 2023-01-06 thomas <div class="header_age_title">Date:</div>
425 b82440e1 2023-01-06 thomas <div class="header_age">
426 b82440e1 2023-01-06 thomas {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
427 b82440e1 2023-01-06 thomas </div>
428 b82440e1 2023-01-06 thomas <div id="header_commit_msg_title">Message:</div>
429 b82440e1 2023-01-06 thomas <div id="header_commit_msg">{{ rc->commit_msg }}</div>
430 b82440e1 2023-01-06 thomas </div>
431 b82440e1 2023-01-06 thomas </div>
432 b82440e1 2023-01-06 thomas <div class="dotted_line"></div>
433 b82440e1 2023-01-06 thomas <div id="blob">
434 b82440e1 2023-01-06 thomas <pre>
435 b82440e1 2023-01-06 thomas {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
436 b82440e1 2023-01-06 thomas </pre>
437 b82440e1 2023-01-06 thomas </div>
438 7ade8b27 2022-12-30 thomas </div>
439 d6795e9f 2022-12-30 thomas {{ end }}
440 d6795e9f 2022-12-30 thomas
441 b82440e1 2023-01-06 thomas {{ define gotweb_render_blob_line(struct template *tp, const char *line,
442 b82440e1 2023-01-06 thomas size_t no) }}
443 b82440e1 2023-01-06 thomas {!
444 b82440e1 2023-01-06 thomas char lineno[16];
445 b82440e1 2023-01-06 thomas int r;
446 b82440e1 2023-01-06 thomas
447 b82440e1 2023-01-06 thomas r = snprintf(lineno, sizeof(lineno), "%zu", no);
448 b82440e1 2023-01-06 thomas if (r < 0 || (size_t)r >= sizeof(lineno))
449 b82440e1 2023-01-06 thomas return -1;
450 b82440e1 2023-01-06 thomas !}
451 b82440e1 2023-01-06 thomas <div class="blob_line" id="line{{ lineno }}">
452 b82440e1 2023-01-06 thomas <div class="blob_number">
453 b82440e1 2023-01-06 thomas <a href="#line{{ lineno }}">{{ lineno }}</a>
454 b82440e1 2023-01-06 thomas </div>
455 b82440e1 2023-01-06 thomas <div class="blob_code">{{ line }}</div>
456 b82440e1 2023-01-06 thomas </div>
457 b82440e1 2023-01-06 thomas {{ end }}
458 b82440e1 2023-01-06 thomas
459 d6795e9f 2022-12-30 thomas {{ define gotweb_render_rss(struct template *tp) }}
460 d6795e9f 2022-12-30 thomas {!
461 d6795e9f 2022-12-30 thomas struct request *c = tp->tp_arg;
462 d6795e9f 2022-12-30 thomas struct server *srv = c->srv;
463 d6795e9f 2022-12-30 thomas struct transport *t = c->t;
464 d6795e9f 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
465 d6795e9f 2022-12-30 thomas struct repo_tag *rt;
466 d6795e9f 2022-12-30 thomas struct gotweb_url summary = {
467 d6795e9f 2022-12-30 thomas .action = SUMMARY,
468 d6795e9f 2022-12-30 thomas .index_page = -1,
469 d6795e9f 2022-12-30 thomas .page = -1,
470 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
471 d6795e9f 2022-12-30 thomas };
472 d6795e9f 2022-12-30 thomas !}
473 d6795e9f 2022-12-30 thomas <?xml version="1.0" encoding="UTF-8"?>
474 d6795e9f 2022-12-30 thomas <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
475 d6795e9f 2022-12-30 thomas <channel>
476 d6795e9f 2022-12-30 thomas <title>Tags of {{ repo_dir->name }}</title>
477 d6795e9f 2022-12-30 thomas <link>
478 d6795e9f 2022-12-30 thomas <![CDATA[
479 d6795e9f 2022-12-30 thomas {{ render gotweb_render_absolute_url(c, &summary) }}
480 d6795e9f 2022-12-30 thomas ]]>
481 d6795e9f 2022-12-30 thomas </link>
482 d6795e9f 2022-12-30 thomas {{ if srv->show_repo_description }}
483 d6795e9f 2022-12-30 thomas <description>{{ repo_dir->description }}</description>
484 d6795e9f 2022-12-30 thomas {{ end }}
485 d6795e9f 2022-12-30 thomas {{ tailq-foreach rt &t->repo_tags entry }}
486 d6795e9f 2022-12-30 thomas {{ render rss_tag_item(tp, rt) }}
487 d6795e9f 2022-12-30 thomas {{ end }}
488 d6795e9f 2022-12-30 thomas </channel>
489 d6795e9f 2022-12-30 thomas </rss>
490 d6795e9f 2022-12-30 thomas {{ end }}
491 d6795e9f 2022-12-30 thomas
492 d6795e9f 2022-12-30 thomas {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
493 d6795e9f 2022-12-30 thomas {!
494 d6795e9f 2022-12-30 thomas struct request *c = tp->tp_arg;
495 d6795e9f 2022-12-30 thomas struct transport *t = c->t;
496 d6795e9f 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
497 d6795e9f 2022-12-30 thomas char *tag_name = rt->tag_name;
498 d6795e9f 2022-12-30 thomas struct gotweb_url tag = {
499 d6795e9f 2022-12-30 thomas .action = TAG,
500 d6795e9f 2022-12-30 thomas .index_page = -1,
501 d6795e9f 2022-12-30 thomas .page = -1,
502 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
503 d6795e9f 2022-12-30 thomas .commit = rt->commit_id,
504 d6795e9f 2022-12-30 thomas };
505 d6795e9f 2022-12-30 thomas
506 d6795e9f 2022-12-30 thomas if (strncmp(tag_name, "refs/tags/", 10) == 0)
507 d6795e9f 2022-12-30 thomas tag_name += 10;
508 d6795e9f 2022-12-30 thomas !}
509 d6795e9f 2022-12-30 thomas <item>
510 d6795e9f 2022-12-30 thomas <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
511 d6795e9f 2022-12-30 thomas <link>
512 d6795e9f 2022-12-30 thomas <![CDATA[
513 d6795e9f 2022-12-30 thomas {{ render gotweb_render_absolute_url(c, &tag) }}
514 d6795e9f 2022-12-30 thomas ]]>
515 d6795e9f 2022-12-30 thomas </link>
516 d6795e9f 2022-12-30 thomas <description>
517 d6795e9f 2022-12-30 thomas <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
518 d6795e9f 2022-12-30 thomas </description>
519 d6795e9f 2022-12-30 thomas {{ render rss_author(tp, rt->tagger) }}
520 d6795e9f 2022-12-30 thomas <guid isPermaLink="false">{{ rt->commit_id }}</guid>
521 d6795e9f 2022-12-30 thomas <pubDate>
522 d6795e9f 2022-12-30 thomas {{ render gotweb_render_age(tp, rt->tagger_time, TM_RFC822) }}
523 d6795e9f 2022-12-30 thomas </pubDate>
524 d6795e9f 2022-12-30 thomas </item>
525 7ade8b27 2022-12-30 thomas {{ end }}
526 d6795e9f 2022-12-30 thomas
527 d6795e9f 2022-12-30 thomas {{ define rss_author(struct template *tp, char *author) }}
528 d6795e9f 2022-12-30 thomas {!
529 d6795e9f 2022-12-30 thomas char *t, *mail;
530 d6795e9f 2022-12-30 thomas
531 d6795e9f 2022-12-30 thomas /* what to do if the author name contains a paren? */
532 d6795e9f 2022-12-30 thomas if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
533 d6795e9f 2022-12-30 thomas return 0;
534 d6795e9f 2022-12-30 thomas
535 d6795e9f 2022-12-30 thomas t = strchr(author, '<');
536 d6795e9f 2022-12-30 thomas if (t == NULL)
537 d6795e9f 2022-12-30 thomas return 0;
538 d6795e9f 2022-12-30 thomas *t = '\0';
539 d6795e9f 2022-12-30 thomas mail = t+1;
540 d6795e9f 2022-12-30 thomas
541 d6795e9f 2022-12-30 thomas while (isspace((unsigned char)*--t))
542 d6795e9f 2022-12-30 thomas *t = '\0';
543 d6795e9f 2022-12-30 thomas
544 d6795e9f 2022-12-30 thomas t = strchr(mail, '>');
545 d6795e9f 2022-12-30 thomas if (t == NULL)
546 d6795e9f 2022-12-30 thomas return 0;
547 d6795e9f 2022-12-30 thomas *t = '\0';
548 d6795e9f 2022-12-30 thomas !}
549 d6795e9f 2022-12-30 thomas <author>
550 d6795e9f 2022-12-30 thomas {{ mail }} {{" "}} ({{ author }})
551 d6795e9f 2022-12-30 thomas </author>
552 d6795e9f 2022-12-30 thomas {{ end }}