3 ed619ca0 2022-12-14 op * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 ed619ca0 2022-12-14 op * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
6 ed619ca0 2022-12-14 op * Permission to use, copy, modify, and distribute this software for any
7 ed619ca0 2022-12-14 op * purpose with or without fee is hereby granted, provided that the above
8 ed619ca0 2022-12-14 op * copyright notice and this permission notice appear in all copies.
10 ed619ca0 2022-12-14 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 ed619ca0 2022-12-14 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 ed619ca0 2022-12-14 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ed619ca0 2022-12-14 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 ed619ca0 2022-12-14 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ed619ca0 2022-12-14 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 ed619ca0 2022-12-14 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 ed619ca0 2022-12-14 op #include <sys/types.h>
20 ed619ca0 2022-12-14 op #include <sys/queue.h>
22 ed619ca0 2022-12-14 op #include <event.h>
23 ed619ca0 2022-12-14 op #include <stdint.h>
24 ed619ca0 2022-12-14 op #include <stdlib.h>
25 ed619ca0 2022-12-14 op #include <string.h>
26 ed619ca0 2022-12-14 op #include <imsg.h>
28 ed619ca0 2022-12-14 op #include "proc.h"
30 ed619ca0 2022-12-14 op #include "gotwebd.h"
31 ed619ca0 2022-12-14 op #include "tmpl.h"
34 ed619ca0 2022-12-14 op gotweb_render_age(struct template *tp, time_t time, int ref_tm)
36 ed619ca0 2022-12-14 op const struct got_error *err;
40 ed619ca0 2022-12-14 op err = gotweb_get_time_str(&age, time, ref_tm);
43 ed619ca0 2022-12-14 op r = tp->tp_puts(tp, age);
50 ed619ca0 2022-12-14 op {{ define gotweb_render_header(struct template *tp) }}
52 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
53 ed619ca0 2022-12-14 op struct server *srv = c->srv;
54 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
55 ed619ca0 2022-12-14 op struct gotweb_url u_path;
56 d19d9fce 2022-12-20 op const char *prfx = c->document_uri;
57 ed619ca0 2022-12-14 op const char *css = srv->custom_css;
59 ed619ca0 2022-12-14 op memset(&u_path, 0, sizeof(u_path));
60 ed619ca0 2022-12-14 op u_path.index_page = -1;
61 ed619ca0 2022-12-14 op u_path.page = -1;
62 ed619ca0 2022-12-14 op u_path.action = SUMMARY;
64 ed619ca0 2022-12-14 op <!doctype html>
67 ed619ca0 2022-12-14 op <meta charset="utf-8" />
68 ed619ca0 2022-12-14 op <title>{{ srv->site_name }}</title>
69 ed619ca0 2022-12-14 op <meta name="viewport" content="initial-scale=.75" />
70 ed619ca0 2022-12-14 op <meta name="msapplication-TileColor" content="#da532c" />
71 ed619ca0 2022-12-14 op <meta name="theme-color" content="#ffffff"/>
72 ed619ca0 2022-12-14 op <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
73 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
74 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
75 ed619ca0 2022-12-14 op <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
76 ed619ca0 2022-12-14 op <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
77 ed619ca0 2022-12-14 op <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
80 ed619ca0 2022-12-14 op <div id="gw_body">
81 ed619ca0 2022-12-14 op <div id="header">
82 ed619ca0 2022-12-14 op <div id="got_link">
83 ed619ca0 2022-12-14 op <a href="{{ srv->logo_url }}" target="_blank">
84 ed619ca0 2022-12-14 op <img src="{{ prfx }}{{ srv->logo }}" />
88 ed619ca0 2022-12-14 op <div id="site_path">
89 ed619ca0 2022-12-14 op <div id="site_link">
90 ed619ca0 2022-12-14 op <a href="?index_page={{ printf "%d", qs->index_page }}">
91 ed619ca0 2022-12-14 op {{ srv->site_link }}
93 ed619ca0 2022-12-14 op {{ if qs->path }}
94 ed619ca0 2022-12-14 op {! u_path.path = qs->path; !}
96 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
97 ed619ca0 2022-12-14 op {{ qs->path }}
100 ed619ca0 2022-12-14 op {{ if qs->action != INDEX }}
101 ed619ca0 2022-12-14 op {{ " / " }}{{ gotweb_action_name(qs->action) }}
105 ed619ca0 2022-12-14 op <div id="content">
108 ed619ca0 2022-12-14 op {{ define gotweb_render_footer(struct template *tp) }}
110 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
111 ed619ca0 2022-12-14 op struct server *srv = c->srv;
113 ed619ca0 2022-12-14 op <div id="site_owner_wrapper">
114 ed619ca0 2022-12-14 op <div id="site_owner">
115 ed619ca0 2022-12-14 op {{ if srv->show_site_owner }}
116 ed619ca0 2022-12-14 op {{ srv->site_owner }}
126 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
128 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
129 ed619ca0 2022-12-14 op struct server *srv = c->srv;
131 ed619ca0 2022-12-14 op <div id="index_header">
132 ed619ca0 2022-12-14 op <div id="index_header_project">
135 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
136 ed619ca0 2022-12-14 op <div id="index_header_description">
140 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
141 ed619ca0 2022-12-14 op <div id="index_header_owner">
145 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
146 ed619ca0 2022-12-14 op <div id="index_header_age">
153 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
155 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
156 ed619ca0 2022-12-14 op struct server *srv = c->srv;
157 ed619ca0 2022-12-14 op struct gotweb_url summary = {
158 ed619ca0 2022-12-14 op .action = SUMMARY,
159 ed619ca0 2022-12-14 op .index_page = -1,
161 ed619ca0 2022-12-14 op .path = repo_dir->name,
162 ed619ca0 2022-12-14 op }, briefs = {
163 ed619ca0 2022-12-14 op .action = BRIEFS,
164 ed619ca0 2022-12-14 op .index_page = -1,
166 ed619ca0 2022-12-14 op .path = repo_dir->name,
167 ed619ca0 2022-12-14 op }, commits = {
168 ed619ca0 2022-12-14 op .action = COMMITS,
169 ed619ca0 2022-12-14 op .index_page = -1,
171 ed619ca0 2022-12-14 op .path = repo_dir->name,
173 ed619ca0 2022-12-14 op .action = TAGS,
174 ed619ca0 2022-12-14 op .index_page = -1,
176 ed619ca0 2022-12-14 op .path = repo_dir->name,
178 ed619ca0 2022-12-14 op .action = TREE,
179 ed619ca0 2022-12-14 op .index_page = -1,
181 ed619ca0 2022-12-14 op .path = repo_dir->name,
184 ed619ca0 2022-12-14 op <div class="index_wrapper">
185 ed619ca0 2022-12-14 op <div class="index_project">
186 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
188 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
189 ed619ca0 2022-12-14 op <div class="index_project_description">
190 ed619ca0 2022-12-14 op {{ repo_dir->description }}
193 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
194 ed619ca0 2022-12-14 op <div class="index_project_owner">
195 ed619ca0 2022-12-14 op {{ repo_dir->owner }}
198 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
199 ed619ca0 2022-12-14 op <div class="index_project_age">
200 ed619ca0 2022-12-14 op {{ repo_dir->age }}
203 ed619ca0 2022-12-14 op <div class="navs_wrapper">
204 ed619ca0 2022-12-14 op <div class="navs">
205 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
207 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
209 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
211 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
213 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
215 ed619ca0 2022-12-14 op <div class="dotted_line"></div>
220 ed619ca0 2022-12-14 op {{ define gotweb_render_briefs(struct template *tp) }}
222 ed619ca0 2022-12-14 op const struct got_error *error;
223 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
224 ed619ca0 2022-12-14 op struct server *srv = c->srv;
225 ed619ca0 2022-12-14 op struct transport *t = c->t;
226 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
227 ed619ca0 2022-12-14 op struct repo_commit *rc;
228 ed619ca0 2022-12-14 op struct repo_dir *repo_dir = t->repo_dir;
229 ed619ca0 2022-12-14 op struct gotweb_url diff_url, tree_url;
232 ed619ca0 2022-12-14 op diff_url = (struct gotweb_url){
233 ed619ca0 2022-12-14 op .action = DIFF,
234 ed619ca0 2022-12-14 op .index_page = -1,
236 ed619ca0 2022-12-14 op .path = repo_dir->name,
237 ed619ca0 2022-12-14 op .headref = qs->headref,
239 ed619ca0 2022-12-14 op tree_url = (struct gotweb_url){
240 ed619ca0 2022-12-14 op .action = TREE,
241 ed619ca0 2022-12-14 op .index_page = -1,
243 ed619ca0 2022-12-14 op .path = repo_dir->name,
244 ed619ca0 2022-12-14 op .headref = qs->headref,
247 ed619ca0 2022-12-14 op if (qs->action == SUMMARY) {
248 ed619ca0 2022-12-14 op qs->action = BRIEFS;
249 ed619ca0 2022-12-14 op error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
251 ed619ca0 2022-12-14 op error = got_get_repo_commits(c, srv->max_commits_display);
255 ed619ca0 2022-12-14 op <div id="briefs_title_wrapper">
256 ed619ca0 2022-12-14 op <div id="briefs_title">Commit Briefs</div>
258 ed619ca0 2022-12-14 op <div id="briefs_content">
259 ed619ca0 2022-12-14 op {{ tailq-foreach rc &t->repo_commits entry }}
261 ed619ca0 2022-12-14 op diff_url.commit = rc->commit_id;
262 ed619ca0 2022-12-14 op tree_url.commit = rc->commit_id;
264 ed619ca0 2022-12-14 op tmp = strchr(rc->author, '<');
268 ed619ca0 2022-12-14 op tmp = strchr(rc->commit_msg, '\n');
272 ed619ca0 2022-12-14 op <div class="briefs_age">
273 ed619ca0 2022-12-14 op {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
275 ed619ca0 2022-12-14 op <div class="briefs_author">
276 ed619ca0 2022-12-14 op {{ rc->author }}
278 ed619ca0 2022-12-14 op <div class="briefs_log">
279 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
280 ed619ca0 2022-12-14 op {{ rc->commit_msg }}
282 ed619ca0 2022-12-14 op {{ if rc->refs_str }}
283 ed619ca0 2022-12-14 op {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
287 ed619ca0 2022-12-14 op <div class="navs_wrapper">
288 ed619ca0 2022-12-14 op <div class="navs">
289 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
291 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
294 ed619ca0 2022-12-14 op <div class="dotted_line"></div>
296 ed619ca0 2022-12-14 op {{ if t->next_id || t->prev_id }}
297 b4c0bd72 2022-12-17 op {{ render gotweb_render_navs(tp) }}
302 b4c0bd72 2022-12-17 op {{ define gotweb_render_navs(struct template *tp) }}
304 b4c0bd72 2022-12-17 op struct request *c = tp->tp_arg;
305 b4c0bd72 2022-12-17 op struct transport *t = c->t;
306 b4c0bd72 2022-12-17 op struct gotweb_url prev, next;
307 b4c0bd72 2022-12-17 op int have_prev, have_next;
309 b4c0bd72 2022-12-17 op gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
311 b4c0bd72 2022-12-17 op <div id="np_wrapper">
312 b4c0bd72 2022-12-17 op <div id="nav_prev">
313 b4c0bd72 2022-12-17 op {{ if have_prev }}
314 b4c0bd72 2022-12-17 op <a href="{{ render gotweb_render_url(c, &prev) }}">
319 b4c0bd72 2022-12-17 op <div id="nav_next">
320 b4c0bd72 2022-12-17 op {{ if have_next }}
321 b4c0bd72 2022-12-17 op <a href="{{ render gotweb_render_url(c, &next) }}">
327 b4c0bd72 2022-12-17 op {{ finally }}
329 b4c0bd72 2022-12-17 op free(t->next_id);
330 b4c0bd72 2022-12-17 op t->next_id = NULL;
331 b4c0bd72 2022-12-17 op free(t->prev_id);
332 b4c0bd72 2022-12-17 op t->prev_id = NULL;
336 156a1144 2022-12-17 op {{ define gotweb_render_commits(struct template *tp) }}
338 156a1144 2022-12-17 op struct request *c = tp->tp_arg;
339 156a1144 2022-12-17 op struct transport *t = c->t;
340 156a1144 2022-12-17 op struct repo_dir *repo_dir = t->repo_dir;
341 156a1144 2022-12-17 op struct repo_commit *rc;
342 156a1144 2022-12-17 op struct gotweb_url diff, tree;
344 156a1144 2022-12-17 op diff = (struct gotweb_url){
345 156a1144 2022-12-17 op .action = DIFF,
346 156a1144 2022-12-17 op .index_page = -1,
348 156a1144 2022-12-17 op .path = repo_dir->name,
350 156a1144 2022-12-17 op tree = (struct gotweb_url){
351 156a1144 2022-12-17 op .action = TREE,
352 156a1144 2022-12-17 op .index_page = -1,
354 156a1144 2022-12-17 op .path = repo_dir->name,
357 156a1144 2022-12-17 op <div class="commits_title_wrapper">
358 156a1144 2022-12-17 op <div class="commits_title">Commits</div>
360 156a1144 2022-12-17 op <div class="commits_content">
361 156a1144 2022-12-17 op {{ tailq-foreach rc &t->repo_commits entry }}
363 156a1144 2022-12-17 op diff.commit = rc->commit_id;
364 156a1144 2022-12-17 op tree.commit = rc->commit_id;
366 156a1144 2022-12-17 op <div class="commits_header_wrapper">
367 156a1144 2022-12-17 op <div class="commits_header">
368 156a1144 2022-12-17 op <div class="header_commit_title">Commit:</div>
369 156a1144 2022-12-17 op <div class="header_commit">{{ rc->commit_id }}</div>
370 156a1144 2022-12-17 op <div class="header_author_title">Author:</div>
371 156a1144 2022-12-17 op <div class="header_author">{{ rc->author }}</div>
372 156a1144 2022-12-17 op <div class="header_age_title">Date:</div>
373 156a1144 2022-12-17 op <div class="header_age">
374 156a1144 2022-12-17 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
378 156a1144 2022-12-17 op <div class="navs_wrapper">
379 156a1144 2022-12-17 op <div class="navs">
380 156a1144 2022-12-17 op <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
382 156a1144 2022-12-17 op <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
385 156a1144 2022-12-17 op <div class="dotted_line"></div>
387 156a1144 2022-12-17 op {{ if t->next_id || t->prev_id }}
388 156a1144 2022-12-17 op {{ render gotweb_render_navs(tp) }}