Blob


1 {!
2 /*
3 * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
5 *
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.
9 *
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.
17 */
19 #include <sys/types.h>
20 #include <sys/queue.h>
22 #include <event.h>
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <imsg.h>
28 #include "proc.h"
30 #include "gotwebd.h"
31 #include "tmpl.h"
33 const struct got_error *gotweb_render_navs(struct request *);
35 static int
36 gotweb_render_age(struct template *tp, time_t time, int ref_tm)
37 {
38 const struct got_error *err;
39 char *age;
40 int r;
42 err = gotweb_get_time_str(&age, time, ref_tm);
43 if (err)
44 return 0;
45 r = tp->tp_puts(tp, age);
46 free(age);
47 return r;
48 }
50 !}
52 {{ define gotweb_render_header(struct template *tp) }}
53 {!
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;
63 u_path.page = -1;
64 u_path.action = SUMMARY;
65 !}
66 <!doctype html>
67 <html>
68 <head>
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 }}" />
80 </head>
81 <body>
82 <div id="gw_body">
83 <div id="header">
84 <div id="got_link">
85 <a href="{{ srv->logo_url }}" target="_blank">
86 <img src="{{ prfx }}{{ srv->logo }}" />
87 </a>
88 </div>
89 </div>
90 <div id="site_path">
91 <div id="site_link">
92 <a href="?index_page={{ printf "%d", qs->index_page }}">
93 {{ srv->site_link }}
94 </a>
95 {{ if qs->path }}
96 {! u_path.path = qs->path; !}
97 {{ " / " }}
98 <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
99 {{ qs->path }}
100 </a>
101 {{ end }}
102 {{ if qs->action != INDEX }}
103 {{ " / " }}{{ gotweb_action_name(qs->action) }}
104 {{ end }}
105 </div>
106 </div>
107 <div id="content">
108 {{ end }}
110 {{ define gotweb_render_footer(struct template *tp) }}
111 {!
112 struct request *c = tp->tp_arg;
113 struct server *srv = c->srv;
114 !}
115 <div id="site_owner_wrapper">
116 <div id="site_owner">
117 {{ if srv->show_site_owner }}
118 {{ srv->site_owner }}
119 {{ end }}
120 </div>
121 </div>
122 </div>
123 </div>
124 </body>
125 </html>
126 {{ end }}
128 {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
129 {!
130 struct request *c = tp->tp_arg;
131 struct server *srv = c->srv;
132 !}
133 <div id="index_header">
134 <div id="index_header_project">
135 Project
136 </div>
137 {{ if srv->show_repo_description }}
138 <div id="index_header_description">
139 Description
140 </div>
141 {{ end }}
142 {{ if srv->show_repo_owner }}
143 <div id="index_header_owner">
144 Owner
145 </div>
146 {{ end }}
147 {{ if srv->show_repo_age }}
148 <div id="index_header_age">
149 Last Change
150 </div>
151 {{ end }}
152 </div>
153 {{ end }}
155 {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
156 {!
157 struct request *c = tp->tp_arg;
158 struct server *srv = c->srv;
159 struct gotweb_url summary = {
160 .action = SUMMARY,
161 .index_page = -1,
162 .page = -1,
163 .path = repo_dir->name,
164 }, briefs = {
165 .action = BRIEFS,
166 .index_page = -1,
167 .page = -1,
168 .path = repo_dir->name,
169 }, commits = {
170 .action = COMMITS,
171 .index_page = -1,
172 .page = -1,
173 .path = repo_dir->name,
174 }, tags = {
175 .action = TAGS,
176 .index_page = -1,
177 .page = -1,
178 .path = repo_dir->name,
179 }, tree = {
180 .action = TREE,
181 .index_page = -1,
182 .page = -1,
183 .path = repo_dir->name,
184 };
185 !}
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>
189 </div>
190 {{ if srv->show_repo_description }}
191 <div class="index_project_description">
192 {{ repo_dir->description }}
193 </div>
194 {{ end }}
195 {{ if srv->show_repo_owner }}
196 <div class="index_project_owner">
197 {{ repo_dir->owner }}
198 </div>
199 {{ end }}
200 {{ if srv->show_repo_age }}
201 <div class="index_project_age">
202 {{ repo_dir->age }}
203 </div>
204 {{ end }}
205 <div class="navs_wrapper">
206 <div class="navs">
207 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
208 {{ " | " }}
209 <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
210 {{ " | " }}
211 <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
212 {{ " | " }}
213 <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
214 {{ " | " }}
215 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
216 </div>
217 <div class="dotted_line"></div>
218 </div>
219 </div>
220 {{ end }}
222 {{ define gotweb_render_briefs(struct template *tp) }}
223 {!
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;
232 char *tmp;
234 diff_url = (struct gotweb_url){
235 .action = DIFF,
236 .index_page = -1,
237 .page = -1,
238 .path = repo_dir->name,
239 .headref = qs->headref,
240 };
241 tree_url = (struct gotweb_url){
242 .action = TREE,
243 .index_page = -1,
244 .page = -1,
245 .path = repo_dir->name,
246 .headref = qs->headref,
247 };
249 if (qs->action == SUMMARY) {
250 qs->action = BRIEFS;
251 error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
252 } else
253 error = got_get_repo_commits(c, srv->max_commits_display);
254 if (error)
255 return -1;
256 !}
257 <div id="briefs_title_wrapper">
258 <div id="briefs_title">Commit Briefs</div>
259 </div>
260 <div id="briefs_content">
261 {{ tailq-foreach rc &t->repo_commits entry }}
262 {!
263 diff_url.commit = rc->commit_id;
264 tree_url.commit = rc->commit_id;
266 tmp = strchr(rc->author, '<');
267 if (tmp)
268 *tmp = '\0';
270 tmp = strchr(rc->commit_msg, '\n');
271 if (tmp)
272 *tmp = '\0';
273 !}
274 <div class="briefs_age">
275 {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
276 </div>
277 <div class="briefs_author">
278 {{ rc->author }}
279 </div>
280 <div class="briefs_log">
281 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
282 {{ rc->commit_msg }}
283 </a>
284 {{ if rc->refs_str }}
285 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
286 {{ end }}
287 </a>
288 </div>
289 <div class="navs_wrapper">
290 <div class="navs">
291 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
292 {{ " | " }}
293 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
294 </div>
295 </div>
296 <div class="dotted_line"></div>
297 {{ end }}
298 {{ if t->next_id || t->prev_id }}
299 {! gotweb_render_navs(c); !}
300 {{ end }}
301 </div>
302 {{ end }}