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