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>
33 const struct got_error *gotweb_render_navs(struct request *);
36 gotweb_render_age(struct template *tp, time_t time, int ref_tm)
38 const struct got_error *err;
42 err = gotweb_get_time_str(&age, time, ref_tm);
45 r = tp->tp_puts(tp, age);
52 {{ define gotweb_render_header(struct template *tp) }}
54 struct request *c = tp->tp_arg;
55 struct server *srv = c->srv;
56 struct querystring *qs = c->t->qs;
57 struct gotweb_url u_path;
58 const char *prfx = c->script_name;
59 const char *css = srv->custom_css;
61 memset(&u_path, 0, sizeof(u_path));
62 u_path.index_page = -1;
64 u_path.action = SUMMARY;
69 <meta charset="utf-8" />
70 <title>{{ srv->site_name }}</title>
71 <meta name="viewport" content="initial-scale=.75" />
72 <meta name="msapplication-TileColor" content="#da532c" />
73 <meta name="theme-color" content="#ffffff"/>
74 <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
75 <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
76 <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
77 <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
78 <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
79 <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
85 <a href="{{ srv->logo_url }}" target="_blank">
86 <img src="{{ prfx }}{{ srv->logo }}" />
92 <a href="?index_page={{ printf "%d", qs->index_page }}">
96 {! u_path.path = qs->path; !}
98 <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
102 {{ if qs->action != INDEX }}
103 {{ " / " }}{{ gotweb_action_name(qs->action) }}
110 {{ define gotweb_render_footer(struct template *tp) }}
112 struct request *c = tp->tp_arg;
113 struct server *srv = c->srv;
115 <div id="site_owner_wrapper">
116 <div id="site_owner">
117 {{ if srv->show_site_owner }}
118 {{ srv->site_owner }}
128 {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
130 struct request *c = tp->tp_arg;
131 struct server *srv = c->srv;
133 <div id="index_header">
134 <div id="index_header_project">
137 {{ if srv->show_repo_description }}
138 <div id="index_header_description">
142 {{ if srv->show_repo_owner }}
143 <div id="index_header_owner">
147 {{ if srv->show_repo_age }}
148 <div id="index_header_age">
155 {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
157 struct request *c = tp->tp_arg;
158 struct server *srv = c->srv;
159 struct gotweb_url summary = {
163 .path = repo_dir->name,
168 .path = repo_dir->name,
173 .path = repo_dir->name,
178 .path = repo_dir->name,
183 .path = repo_dir->name,
186 <div class="index_wrapper">
187 <div class="index_project">
188 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
190 {{ if srv->show_repo_description }}
191 <div class="index_project_description">
192 {{ repo_dir->description }}
195 {{ if srv->show_repo_owner }}
196 <div class="index_project_owner">
197 {{ repo_dir->owner }}
200 {{ if srv->show_repo_age }}
201 <div class="index_project_age">
205 <div class="navs_wrapper">
207 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
209 <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
211 <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
213 <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
215 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
217 <div class="dotted_line"></div>
222 {{ define gotweb_render_briefs(struct template *tp) }}
224 const struct got_error *error;
225 struct request *c = tp->tp_arg;
226 struct server *srv = c->srv;
227 struct transport *t = c->t;
228 struct querystring *qs = c->t->qs;
229 struct repo_commit *rc;
230 struct repo_dir *repo_dir = t->repo_dir;
231 struct gotweb_url diff_url, tree_url;
234 diff_url = (struct gotweb_url){
238 .path = repo_dir->name,
239 .headref = qs->headref,
241 tree_url = (struct gotweb_url){
245 .path = repo_dir->name,
246 .headref = qs->headref,
249 if (qs->action == SUMMARY) {
251 error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
253 error = got_get_repo_commits(c, srv->max_commits_display);
257 <div id="briefs_title_wrapper">
258 <div id="briefs_title">Commit Briefs</div>
260 <div id="briefs_content">
261 {{ tailq-foreach rc &t->repo_commits entry }}
263 diff_url.commit = rc->commit_id;
264 tree_url.commit = rc->commit_id;
266 tmp = strchr(rc->author, '<');
270 tmp = strchr(rc->commit_msg, '\n');
274 <div class="briefs_age">
275 {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
277 <div class="briefs_author">
280 <div class="briefs_log">
281 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
284 {{ if rc->refs_str }}
285 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
289 <div class="navs_wrapper">
291 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
293 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
296 <div class="dotted_line"></div>
298 {{ if t->next_id || t->prev_id }}
299 {! gotweb_render_navs(c); !}