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 static inline int rss_tag_item(struct template *, struct repo_tag *);
35 static inline int rss_author(struct template *, char *);
38 gotweb_render_age(struct template *tp, time_t time, int ref_tm)
40 const struct got_error *err;
44 err = gotweb_get_time_str(&age, time, ref_tm);
47 r = tp->tp_puts(tp, age);
54 {{ define gotweb_render_header(struct template *tp) }}
56 struct request *c = tp->tp_arg;
57 struct server *srv = c->srv;
58 struct querystring *qs = c->t->qs;
59 struct gotweb_url u_path;
60 const char *prfx = c->document_uri;
61 const char *css = srv->custom_css;
63 memset(&u_path, 0, sizeof(u_path));
64 u_path.index_page = -1;
66 u_path.action = SUMMARY;
71 <meta charset="utf-8" />
72 <title>{{ srv->site_name }}</title>
73 <meta name="viewport" content="initial-scale=.75" />
74 <meta name="msapplication-TileColor" content="#da532c" />
75 <meta name="theme-color" content="#ffffff"/>
76 <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
77 <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
78 <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
79 <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
80 <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
81 <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
87 <a href="{{ srv->logo_url }}" target="_blank">
88 <img src="{{ prfx }}{{ srv->logo }}" />
94 <a href="?index_page={{ printf "%d", qs->index_page }}">
98 {! u_path.path = qs->path; !}
100 <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
104 {{ if qs->action != INDEX }}
105 {{ " / " }}{{ gotweb_action_name(qs->action) }}
112 {{ define gotweb_render_footer(struct template *tp) }}
114 struct request *c = tp->tp_arg;
115 struct server *srv = c->srv;
117 <div id="site_owner_wrapper">
118 <div id="site_owner">
119 {{ if srv->show_site_owner }}
120 {{ srv->site_owner }}
130 {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
132 struct request *c = tp->tp_arg;
133 struct server *srv = c->srv;
135 <div id="index_header">
136 <div id="index_header_project">
139 {{ if srv->show_repo_description }}
140 <div id="index_header_description">
144 {{ if srv->show_repo_owner }}
145 <div id="index_header_owner">
149 {{ if srv->show_repo_age }}
150 <div id="index_header_age">
157 {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
159 struct request *c = tp->tp_arg;
160 struct server *srv = c->srv;
161 struct gotweb_url summary = {
165 .path = repo_dir->name,
170 .path = repo_dir->name,
175 .path = repo_dir->name,
180 .path = repo_dir->name,
185 .path = repo_dir->name,
190 .path = repo_dir->name,
193 <div class="index_wrapper">
194 <div class="index_project">
195 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
197 {{ if srv->show_repo_description }}
198 <div class="index_project_description">
199 {{ repo_dir->description }}
202 {{ if srv->show_repo_owner }}
203 <div class="index_project_owner">
204 {{ repo_dir->owner }}
207 {{ if srv->show_repo_age }}
208 <div class="index_project_age">
212 <div class="navs_wrapper">
214 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
216 <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
218 <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
220 <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
222 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
224 <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
226 <div class="dotted_line"></div>
231 {{ define gotweb_render_briefs(struct template *tp) }}
233 const struct got_error *error;
234 struct request *c = tp->tp_arg;
235 struct server *srv = c->srv;
236 struct transport *t = c->t;
237 struct querystring *qs = c->t->qs;
238 struct repo_commit *rc;
239 struct repo_dir *repo_dir = t->repo_dir;
240 struct gotweb_url diff_url, tree_url;
243 diff_url = (struct gotweb_url){
247 .path = repo_dir->name,
248 .headref = qs->headref,
250 tree_url = (struct gotweb_url){
254 .path = repo_dir->name,
255 .headref = qs->headref,
258 if (qs->action == SUMMARY) {
260 error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
262 error = got_get_repo_commits(c, srv->max_commits_display);
266 <div id="briefs_title_wrapper">
267 <div id="briefs_title">Commit Briefs</div>
269 <div id="briefs_content">
270 {{ tailq-foreach rc &t->repo_commits entry }}
272 diff_url.commit = rc->commit_id;
273 tree_url.commit = rc->commit_id;
275 tmp = strchr(rc->author, '<');
279 tmp = strchr(rc->commit_msg, '\n');
283 <div class="briefs_age">
284 {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
286 <div class="briefs_author">
289 <div class="briefs_log">
290 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
293 {{ if rc->refs_str }}
294 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
298 <div class="navs_wrapper">
300 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
302 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
305 <div class="dotted_line"></div>
307 {{ if t->next_id || t->prev_id }}
308 {{ render gotweb_render_navs(tp) }}
313 {{ define gotweb_render_navs(struct template *tp) }}
315 struct request *c = tp->tp_arg;
316 struct transport *t = c->t;
317 struct gotweb_url prev, next;
318 int have_prev, have_next;
320 gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
322 <div id="np_wrapper">
325 <a href="{{ render gotweb_render_url(c, &prev) }}">
332 <a href="{{ render gotweb_render_url(c, &next) }}">
347 {{ define gotweb_render_commits(struct template *tp) }}
349 struct request *c = tp->tp_arg;
350 struct transport *t = c->t;
351 struct repo_dir *repo_dir = t->repo_dir;
352 struct repo_commit *rc;
353 struct gotweb_url diff, tree;
355 diff = (struct gotweb_url){
359 .path = repo_dir->name,
361 tree = (struct gotweb_url){
365 .path = repo_dir->name,
368 <div class="commits_title_wrapper">
369 <div class="commits_title">Commits</div>
371 <div class="commits_content">
372 {{ tailq-foreach rc &t->repo_commits entry }}
374 diff.commit = rc->commit_id;
375 tree.commit = rc->commit_id;
377 <div class="commits_header_wrapper">
378 <div class="commits_header">
379 <div class="header_commit_title">Commit:</div>
380 <div class="header_commit">{{ rc->commit_id }}</div>
381 <div class="header_author_title">Author:</div>
382 <div class="header_author">{{ rc->author }}</div>
383 <div class="header_age_title">Date:</div>
384 <div class="header_age">
385 {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
389 <div class="dotted_line"></div>
394 <div class="navs_wrapper">
396 <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
398 <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
401 <div class="dotted_line"></div>
403 {{ if t->next_id || t->prev_id }}
404 {{ render gotweb_render_navs(tp) }}
409 {{ define gotweb_render_rss(struct template *tp) }}
411 struct request *c = tp->tp_arg;
412 struct server *srv = c->srv;
413 struct transport *t = c->t;
414 struct repo_dir *repo_dir = t->repo_dir;
416 struct gotweb_url summary = {
420 .path = repo_dir->name,
423 <?xml version="1.0" encoding="UTF-8"?>
424 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
426 <title>Tags of {{ repo_dir->name }}</title>
429 {{ render gotweb_render_absolute_url(c, &summary) }}
432 {{ if srv->show_repo_description }}
433 <description>{{ repo_dir->description }}</description>
435 {{ tailq-foreach rt &t->repo_tags entry }}
436 {{ render rss_tag_item(tp, rt) }}
442 {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
444 struct request *c = tp->tp_arg;
445 struct transport *t = c->t;
446 struct repo_dir *repo_dir = t->repo_dir;
447 char *tag_name = rt->tag_name;
448 struct gotweb_url tag = {
452 .path = repo_dir->name,
453 .commit = rt->commit_id,
456 if (strncmp(tag_name, "refs/tags/", 10) == 0)
460 <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
463 {{ render gotweb_render_absolute_url(c, &tag) }}
467 <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
469 {{ render rss_author(tp, rt->tagger) }}
470 <guid isPermaLink="false">{{ rt->commit_id }}</guid>
472 {{ render gotweb_render_age(tp, rt->tagger_time, TM_RFC822) }}
477 {{ define rss_author(struct template *tp, char *author) }}
481 /* what to do if the author name contains a paren? */
482 if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
485 t = strchr(author, '<');
491 while (isspace((unsigned char)*--t))
494 t = strchr(mail, '>');
500 {{ mail }} {{" "}} ({{ author }})