gotwebd: provide gotweb_render_page() entrypoint for all pages
[got-portable.git] / gotwebd / pages.tmpl
blobd092e3fbcc837ec5abd7684b0cb9de5e0562319c
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 "got_compat.h"
21 #include <sys/types.h>
22 #include <sys/queue.h>
23 #include <sys/stat.h>
25 #include <ctype.h>
26 #include <event.h>
27 #include <stdint.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <imsg.h>
33 #include "got_error.h"
34 #include "got_object.h"
35 #include "got_reference.h"
37 #include "proc.h"
39 #include "gotwebd.h"
40 #include "tmpl.h"
42 static int gotweb_render_blob_line(struct template *, const char *, size_t);
43 static int gotweb_render_tree_item(struct template *, struct got_tree_entry *);
44 static int blame_line(struct template *, const char *, struct blame_line *,
45     int, int);
47 static inline int gotweb_render_more(struct template *, int);
49 static inline int diff_line(struct template *, char *);
50 static inline int tag_item(struct template *, struct repo_tag *);
51 static inline int branch(struct template *, struct got_reflist_entry *);
52 static inline int rss_tag_item(struct template *, struct repo_tag *);
53 static inline int rss_author(struct template *, char *);
57 {{ define gotweb_render_page(struct template *tp,
58     int (*body)(struct template *)) }}
60         struct request          *c = tp->tp_arg;
61         struct server           *srv = c->srv;
62         struct querystring      *qs = c->t->qs;
63         struct gotweb_url        u_path;
64         const char              *prfx = c->document_uri;
65         const char              *css = srv->custom_css;
67         memset(&u_path, 0, sizeof(u_path));
68         u_path.index_page = -1;
69         u_path.page = -1;
70         u_path.action = SUMMARY;
72 <!doctype html>
73 <html>
74   <head>
75     <meta charset="utf-8" />
76     <title>{{ srv->site_name }}</title>
77     <meta name="viewport" content="initial-scale=.75" />
78     <meta name="msapplication-TileColor" content="#da532c" />
79     <meta name="theme-color" content="#ffffff"/>
80     <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
81     <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
82     <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
83     <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
84     <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
85     <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
86   </head>
87   <body>
88     <div id="gw_body">
89       <div id="header">
90         <div id="got_link">
91           <a href="{{ srv->logo_url }}" target="_blank">
92             <img src="{{ prfx }}{{ srv->logo }}" />
93           </a>
94         </div>
95       </div>
96       <div id="site_path">
97         <div id="site_link">
98           <a href="?index_page={{ printf "%d", qs->index_page }}">
99             {{ srv->site_link }}
100           </a>
101           {{ if qs->path }}
102             {! u_path.path = qs->path; !}
103             {{ " / " }}
104             <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
105               {{ qs->path }}
106             </a>
107           {{ end }}
108           {{ if qs->action != INDEX }}
109             {{ " / " }}{{ gotweb_action_name(qs->action) }}
110           {{ end }}
111         </div>
112       </div>
113       <div id="content">
114         {{ render body(tp) }}
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) }}
130         struct request *c = tp->tp_arg;
131         struct server *srv = c->srv;
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) }}
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         }, rss = {
185                 .action = RSS,
186                 .index_page = -1,
187                 .page = -1,
188                 .path = repo_dir->name,
189         };
191 <div class="index_wrapper">
192   <div class="index_project">
193     <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
194   </div>
195   {{ if srv->show_repo_description }}
196     <div class="index_project_description">
197       {{ repo_dir->description }}
198     </div>
199   {{ end }}
200   {{ if srv->show_repo_owner }}
201     <div class="index_project_owner">
202       {{ repo_dir->owner }}
203     </div>
204   {{ end }}
205   {{ if srv->show_repo_age }}
206     <div class="index_project_age">
207       {{ render gotweb_render_age(tp, repo_dir->age, TM_DIFF) }}
208     </div>
209   {{ end }}
210   <div class="navs_wrapper">
211     <div class="navs">
212       <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
213       {{ " | " }}
214       <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
215       {{ " | " }}
216       <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
217       {{ " | " }}
218       <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
219       {{ " | " }}
220       <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
221       {{ " | " }}
222       <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
223     </div>
224     <div class="dotted_line"></div>
225   </div>
226 </div>
227 {{ end }}
229 {{ define gotweb_render_briefs(struct template *tp) }}
231         const struct got_error  *error;
232         struct request          *c = tp->tp_arg;
233         struct server           *srv = c->srv;
234         struct transport        *t = c->t;
235         struct querystring      *qs = c->t->qs;
236         struct repo_commit      *rc;
237         struct repo_dir         *repo_dir = t->repo_dir;
238         struct gotweb_url        diff_url, tree_url;
239         char                    *tmp;
241         diff_url = (struct gotweb_url){
242                 .action = DIFF,
243                 .index_page = -1,
244                 .page = -1,
245                 .path = repo_dir->name,
246                 .headref = qs->headref,
247         };
248         tree_url = (struct gotweb_url){
249                 .action = TREE,
250                 .index_page = -1,
251                 .page = -1,
252                 .path = repo_dir->name,
253                 .headref = qs->headref,
254         };
256         if (qs->action == SUMMARY) {
257                 qs->action = BRIEFS;
258                 error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
259         } else
260                 error = got_get_repo_commits(c, srv->max_commits_display);
261         if (error)
262                 return -1;
264 <div id="briefs_title_wrapper">
265   <div id="briefs_title">Commit Briefs</div>
266 </div>
267 <div id="briefs_content">
268   {{ tailq-foreach rc &t->repo_commits entry }}
269     {!
270         diff_url.commit = rc->commit_id;
271         tree_url.commit = rc->commit_id;
273         tmp = strchr(rc->committer, '<');
274         if (tmp)
275                 *tmp = '\0';
277         tmp = strchr(rc->commit_msg, '\n');
278         if (tmp)
279                 *tmp = '\0';
280     !}
281     <div class="briefs_age">
282       {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
283     </div>
284     <div class="briefs_author">
285       {{ rc->committer }}
286     </div>
287     <div class="briefs_log">
288       <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
289         {{ rc->commit_msg }}
290       </a>
291       {{ if rc->refs_str }}
292         {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
293       {{ end }}
294       </a>
295     </div>
296     <div class="navs_wrapper">
297       <div class="navs">
298         <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
299         {{ " | " }}
300         <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
301       </div>
302     </div>
303     <div class="dotted_line"></div>
304   {{ end }}
305   {{ render gotweb_render_more(tp, BRIEFS) }}
306 </div>
307 {{ end }}
309 {{ define gotweb_render_more(struct template *tp, int action) }}
311         struct request          *c = tp->tp_arg;
312         struct transport        *t = c->t;
313         struct querystring      *qs = t->qs;
314         struct gotweb_url        more = {
315                 .action = action,
316                 .index_page = -1,
317                 .path = qs->path,
318                 .commit = t->more_id,
319                 .headref = qs->headref,
320         };
322   {{ if t->more_id }}
323     <div id="np_wrapper">
324       <div id="nav_more">
325         <a href="{{ render gotweb_render_url(c, &more) }}">
326           More&nbsp;&darr;
327         </a>
328       </div>
329     </div>
330   {{ end }}
331 {{ end }}
333 {{ define gotweb_render_navs(struct template *tp) }}
335         struct request          *c = tp->tp_arg;
336         struct transport        *t = c->t;
337         struct gotweb_url        prev, next;
338         int                      have_prev, have_next;
340         gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
342 <div id="np_wrapper">
343   <div id="nav_prev">
344     {{ if have_prev }}
345       <a href="{{ render gotweb_render_url(c, &prev) }}">
346         Previous
347       </a>
348     {{ end }}
349   </div>
350   <div id="nav_next">
351     {{ if have_next }}
352       <a href="{{ render gotweb_render_url(c, &next) }}">
353         Next
354       </a>
355     {{ end }}
356   </div>
357 </div>
358 {{ finally }}
360         free(t->next_id);
361         t->next_id = NULL;
362         free(t->prev_id);
363         t->prev_id = NULL;
365 {{ end }}
367 {{ define gotweb_render_commits(struct template *tp) }}
369         struct request          *c = tp->tp_arg;
370         struct transport        *t = c->t;
371         struct repo_dir         *repo_dir = t->repo_dir;
372         struct repo_commit      *rc;
373         struct gotweb_url        diff, tree;
375         diff = (struct gotweb_url){
376                 .action = DIFF,
377                 .index_page = -1,
378                 .page = -1,
379                 .path = repo_dir->name,
380         };
381         tree = (struct gotweb_url){
382                 .action = TREE,
383                 .index_page = -1,
384                 .page = -1,
385                 .path = repo_dir->name,
386         };
388 <div class="commits_title_wrapper">
389   <div class="commits_title">Commits</div>
390 </div>
391 <div class="commits_content">
392   {{ tailq-foreach rc &t->repo_commits entry }}
393     {!
394         diff.commit = rc->commit_id;
395         tree.commit = rc->commit_id;
396     !}
397     <div class="commits_header_wrapper">
398       <div class="commits_header">
399         <div class="header_commit_title">Commit:</div>
400         <div class="header_commit">{{ rc->commit_id }}</div>
401         <div class="header_author_title">From:</div>
402         <div class="header_author">{{ rc->author }}</div>
403         {{ if strcmp(rc->committer, rc->author) != 0 }}
404           <div class="header_author_title">Via:</div>
405           <div class="header_author">{{ rc->committer }}</div>
406         {{ end }}
407         <div class="header_age_title">Date:</div>
408         <div class="header_age">
409           {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
410         </div>
411       </div>
412     </div>
413     <div class="dotted_line"></div>
414     <div class="commit">
415       {{ "\n" }}
416       {{ rc->commit_msg }}
417     </div>
418     <div class="navs_wrapper">
419       <div class="navs">
420         <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
421         {{ " | " }}
422         <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
423       </div>
424     </div>
425     <div class="dotted_line"></div>
426   {{ end }}
427   {{ render gotweb_render_more(tp, COMMITS) }}
428 </div>
429 {{ end }}
431 {{ define gotweb_render_blob(struct template *tp) }}
433         struct request          *c = tp->tp_arg;
434         struct transport        *t = c->t;
435         struct got_blob_object  *blob = t->blob;
436         struct repo_commit      *rc = TAILQ_FIRST(&t->repo_commits);
438 <div id="blob_title_wrapper">
439   <div id="blob_title">Blob</div>
440 </div>
441 <div id="blob_content">
442   <div id="blob_header_wrapper">
443     <div id="blob_header">
444       <div class="header_age_title">Date:</div>
445       <div class="header_age">
446         {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
447       </div>
448       <div id="header_commit_msg_title">Message:</div>
449       <div id="header_commit_msg">{{ rc->commit_msg }}</div>
450     </div>
451   </div>
452   <div class="dotted_line"></div>
453   <div id="blob">
454     <pre>
455       {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
456     </pre>
457   </div>
458 </div>
459 {{ end }}
461 {{ define gotweb_render_blob_line(struct template *tp, const char *line,
462     size_t no) }}
464         char             lineno[16];
465         int              r;
467         r = snprintf(lineno, sizeof(lineno), "%zu", no);
468         if (r < 0 || (size_t)r >= sizeof(lineno))
469                 return -1;
471 <div class="blob_line" id="line{{ lineno }}">
472   <div class="blob_number">
473     <a href="#line{{ lineno }}">{{ lineno }}</a>
474   </div>
475   <div class="blob_code">{{ line }}</div>
476 </div>
477 {{ end }}
479 {{ define gotweb_render_tree(struct template *tp) }}
481         struct request          *c = tp->tp_arg;
482         struct transport        *t = c->t;
483         struct repo_commit      *rc = TAILQ_FIRST(&t->repo_commits);
485 <div id="tree_title_wrapper">
486   <div id="tree_title">Tree</div>
487 </div>
488 <div id="tree_content">
489   <div id="tree_header_wrapper">
490     <div id="tree_header">
491       <div id="header_tree_title">Tree:</div>
492       <div id="header_tree">{{ rc->tree_id }}</div>
493       <div class="header_age_title">Date:</div>
494       <div class="header_age">
495         {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
496       </div>
497       <div id="header_commit_msg_title">Message:</div>
498       <div id="header_commit_msg">{{ rc->commit_msg }}</div>
499     </div>
500   </div>
501   <div class="dotted_line"></div>
502   <div id="tree">
503     {{ render got_output_repo_tree(c, gotweb_render_tree_item) }}
504   </div>
505 </div>
506 {{ end }}
508 {{ define gotweb_render_tree_item(struct template *tp,
509     struct got_tree_entry *te) }}
511         struct request          *c = tp->tp_arg;
512         struct transport        *t = c->t;
513         struct querystring      *qs = t->qs;
514         struct repo_commit      *rc = TAILQ_FIRST(&t->repo_commits);
515         const char              *modestr = "";
516         const char              *name;
517         const char              *folder;
518         char                    *dir = NULL;
519         mode_t                   mode;
520         struct gotweb_url        url = {
521                .index_page = -1,
522                .page = -1,
523                .commit = rc->commit_id,
524                .path = qs->path,
525         };
527         name = got_tree_entry_get_name(te);
528         mode = got_tree_entry_get_mode(te);
530         folder = qs->folder ? qs->folder : "";
531         if (S_ISDIR(mode)) {
532                 if (asprintf(&dir, "%s/%s", folder, name) == -1)
533                         return (-1);
535                 url.action = TREE;
536                 url.folder = dir;
537         } else {
538                 url.action = BLOB;
539                 url.folder = folder;
540                 url.file = name;
541         }
543         if (got_object_tree_entry_is_submodule(te))
544                 modestr = "$";
545         else if (S_ISLNK(mode))
546                 modestr = "@";
547         else if (S_ISDIR(mode))
548                 modestr = "/";
549         else if (mode & S_IXUSR)
550                 modestr = "*";
552 <div class="tree_wrapper">
553   {{ if S_ISDIR(mode) }}
554     <div class="tree_line">
555       <a href="{{ render gotweb_render_url(c, &url) }}">
556         {{ name }}{{ modestr }}
557       </a>
558     </div>
559     <div class="tree_line_blank">&nbsp;</div>
560   {{ else }}
561     <div class="tree_line">
562       <a href="{{ render gotweb_render_url(c, &url) }}">
563         {{ name }}{{ modestr }}
564       </a>
565     </div>
566     <div class="tree_line_blank">
567       {! url.action = COMMITS; !}
568       <a href="{{ render gotweb_render_url(c, &url) }}">
569         commits
570       </a>
571       {{ " | " }}
572       {! url.action = BLAME; !}
573       <a href="{{ render gotweb_render_url(c, &url) }}">
574         blame
575       </a>
576     </div>
577   {{ end }}
578 </div>
579 {{ finally }}
581         free(dir);
583 {{ end }}
585 {{ define gotweb_render_tags(struct template *tp) }}
587         struct request          *c = tp->tp_arg;
588         struct transport        *t = c->t;
589         struct querystring      *qs = t->qs;
590         struct repo_tag         *rt;
591         int                      commit_found;
593         commit_found = qs->commit == NULL;
595 <div id="tags_title_wrapper">
596   <div id="tags_title">Tags</div>
597 </div>
598 <div id="tags_content">
599   {{ if t->tag_count == 0 }}
600     <div id="err_content">
601       This repository contains no tags
602     </div>
603   {{ else }}
604     {{ tailq-foreach rt &t->repo_tags entry }}
605       {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
606         {! commit_found = 1; !}
607         {{ render tag_item(tp, rt) }}
608       {{ end }}
609     {{ end }}
610     {{ if t->next_id || t->prev_id }}
611       {! qs->action = TAGS; !}
612       {{ render gotweb_render_navs(tp) }}
613     {{ end }}
614   {{ end }}
615 </div>
616 {{ end }}
618 {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
620         struct request          *c = tp->tp_arg;
621         struct transport        *t = c->t;
622         struct repo_dir         *repo_dir = t->repo_dir;
623         char                    *tag_name = rt->tag_name;
624         char                    *msg = rt->tag_commit;
625         char                    *nl;
626         struct gotweb_url        url = {
627                 .action = TAG,
628                 .index_page = -1,
629                 .page = -1,
630                 .path = repo_dir->name,
631                 .commit = rt->commit_id,
632         };
634         if (strncmp(tag_name, "refs/tags/", 10) == 0)
635                 tag_name += 10;
637         if (msg) {
638                 nl = strchr(msg, '\n');
639                 if (nl)
640                         *nl = '\0';
641         }
643 <div class="tag_age">
644   {{ render gotweb_render_age(tp, rt->tagger_time, TM_DIFF) }}
645 </div>
646 <div class="tag">{{ tag_name }}</div>
647 <div class="tag_log">
648   <a href="{{ render gotweb_render_url(c, &url) }}">
649     {{ msg }}
650   </a>
651 </div>
652 <div class="navs_wrapper">
653   <div class="navs">
654     <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
655     {{ " | " }}
656     {! url.action = BRIEFS; !}
657     <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
658     {{ " | " }}
659     {! url.action = COMMITS; !}
660     <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
661   </div>
662 </div>
663 <div class="dotted_line"></div>
664 {{ end }}
666 {{ define gotweb_render_tag(struct template *tp) }}
668         struct request          *c = tp->tp_arg;
669         struct transport        *t = c->t;
670         struct repo_tag         *rt;
671         const char              *tag_name;
673         rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
674         tag_name = rt->tag_name;
676         if (strncmp(tag_name, "refs/", 5) == 0)
677                 tag_name += 5;
679 <div id="tags_title_wrapper">
680   <div id="tags_title">Tag</div>
681 </div>
682 <div id="tags_content">
683   <div id="tag_header_wrapper">
684     <div id="tag_header">
685       <div class="header_commit_title">Commit:</div>
686       <div class="header_commit">
687         {{ rt->commit_id }}
688         {{ " " }}
689         <span class="refs_str">({{ tag_name }})</span>
690       </div>
691       <div class="header_author_title">Tagger:</div>
692       <div class="header_author">{{ rt->tagger }}</div>
693       <div class="header_age_title">Date:</div>
694       <div class="header_age">
695         {{ render gotweb_render_age(tp, rt->tagger_time, TM_LONG)}}
696       </div>
697       <div id="header_commit_msg_title">Message:</div>
698       <div id="header_commit_msg">{{ rt->commit_msg }}</div>
699     </div>
700     <div class="dotted_line"></div>
701     <div id="tag_commit">
702       {{ "\n" }}
703       {{ rt->tag_commit }}
704     </div>
705   </div>
706 </div>
707 {{ end }}
709 {{ define gotweb_render_diff(struct template *tp) }}
711         struct request          *c = tp->tp_arg;
712         struct transport        *t = c->t;
713         FILE                    *fp = t->fp;
714         struct repo_commit      *rc = TAILQ_FIRST(&t->repo_commits);
715         char                    *line = NULL;
716         size_t                   linesize = 0;
717         ssize_t                  linelen;
719 <div id="diff_title_wrapper">
720   <div id="diff_title">Commit Diff</div>
721 </div>
722 <div id="diff_content">
723   <div id="diff_header_wrapper">
724     <div id="diff_header">
725       <div class="header_commit_title">Commit:</div>
726       <div class="header_commit">{{ rc->commit_id }}</div>
727       <div class="header_author_title">From:</div>
728       <div class="header_author">{{ rc->author }}</div>
729       {{ if strcmp(rc->committer, rc->author) != 0 }}
730         <div class="header_author_title">Via:</div>
731         <div class="header_author">{{ rc->committer }}</div>
732       {{ end }}
733       <div class="header_age_title">Date:</div>
734       <div class="header_age">
735         {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
736       </div>
737       <div id="header_commit_msg_title">Message:</div>
738       <div id="header_commit_msg">{{ rc->commit_msg }}</div>
739     </div>
740   </div>
741   <div class="dotted_line"></div>
742   <div id="diff">
743     {{ "\n" }}
744     {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
745       {{ render diff_line(tp, line) }}
746     {{ end }}
747   </div>
748 </div>
749 {{ finally }}
750 {! free(line); !}
751 {{ end }}
753 {{ define diff_line(struct template *tp, char *line )}}
755         const char              *color = NULL;
756         char                    *nl;
758         if (!strncmp(line, "-", 1))
759                 color = "diff_minus";
760         else if (!strncmp(line, "+", 1))
761                 color = "diff_plus";
762         else if (!strncmp(line, "@@", 2))
763                 color = "diff_chunk_header";
764         else if (!strncmp(line, "commit +", 8) ||
765             !strncmp(line, "commit -", 8) ||
766             !strncmp(line, "blob +", 6) ||
767             !strncmp(line, "blob -", 6) ||
768             !strncmp(line, "file +", 6) ||
769             !strncmp(line, "file -", 6))
770                 color = "diff_meta";
771         else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
772                 color = "diff_author";
773         else if (!strncmp(line, "date:", 5))
774                 color = "diff_date";
776         nl = strchr(line, '\n');
777         if (nl)
778                 *nl = '\0';
780 <div class="diff_line {{ color }}">{{ line }}</div>
781 {{ end }}
783 {{ define gotweb_render_branches(struct template *tp,
784     struct got_reflist_head *refs) }}
786         struct got_reflist_entry        *re;
788 <div id="branches_title_wrapper">
789   <div id="branches_title">Branches</div>
790 </div>
791 <div id="branches_content">
792   {{ tailq-foreach re refs entry }}
793     {{ if !got_ref_is_symbolic(re->ref) }}
794       {{ render branch(tp, re) }}
795     {{ end }}
796   {{ end }}
797 </div>
798 {{ end }}
800 {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
802         const struct got_error  *err;
803         struct request          *c = tp->tp_arg;
804         struct querystring      *qs = c->t->qs;
805         const char              *refname;
806         time_t                   age;
807         struct gotweb_url        url = {
808                 .action = SUMMARY,
809                 .index_page = -1,
810                 .page = -1,
811                 .path = qs->path,
812         };
814         refname = got_ref_get_name(re->ref);
816         err = got_get_repo_age(&age, c, refname);
817         if (err) {
818                 log_warnx("%s: %s", __func__, err->msg);
819                 return -1;
820         }
822         if (strncmp(refname, "refs/heads/", 11) == 0)
823                 refname += 11;
825         url.headref = refname;
827 <div class="branches_wrapper">
828   <div class="branches_age">
829     {{ render gotweb_render_age(tp, age, TM_DIFF) }}
830   </div>
831   <div class="branches_space">&nbsp;</div>
832   <div class="branch">
833     <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
834   </div>
835   <div class="navs_wrapper">
836     <div class="navs">
837       <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
838       {{" | "}}
839       {! url.action = BRIEFS; !}
840       <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
841       {{" | "}}
842       {! url.action = COMMITS; !}
843       <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
844     </div>
845   </div>
846   <div class="dotted_line"></div>
847 </div>
848 {{ end }}
850 {{ define gotweb_render_summary(struct template *tp) }}
852         struct request          *c = tp->tp_arg;
853         struct server           *srv = c->srv;
854         struct transport        *t = c->t;
855         struct got_reflist_head *refs = &t->refs;
857 <div id="summary_wrapper">
858   {{ if srv->show_repo_description }}
859     <div id="description_title">Description:</div>
860     <div id="description">{{ t->repo_dir->description }}</div>
861   {{ end }}
862   {{ if srv->show_repo_owner }}
863     <div id="repo_owner_title">Owner:</div>
864     <div id="repo_owner">{{ t->repo_dir->owner }}</div>
865   {{ end }}
866   {{ if srv->show_repo_age }}
867     <div id="last_change_title">Last Change:</div>
868     <div id="last_change">
869       {{ render gotweb_render_age(tp, t->repo_dir->age, TM_DIFF) }}
870     </div>
871   {{ end }}
872   {{ if srv->show_repo_cloneurl }}
873     <div id="cloneurl_title">Clone URL:</div>
874     <div id="cloneurl">{{ t->repo_dir->url }}</div>
875   {{ end }}
876 </div>
877 {{ render gotweb_render_briefs(tp) }}
878 {{ render gotweb_render_tags(tp) }}
879 {{ render gotweb_render_branches(tp, refs) }}
880 {{ end }}
882 {{ define gotweb_render_blame(struct template *tp) }}
884         const struct got_error  *err;
885         struct request          *c = tp->tp_arg;
886         struct transport        *t = c->t;
887         struct repo_commit      *rc = TAILQ_FIRST(&t->repo_commits);
889 <div id="blame_title_wrapper">
890   <div id="blame_title">Blame</div>
891 </div>
892 <div id="blame_content">
893   <div id="blame_header_wrapper">
894     <div id="blame_header">
895       <div class="header_age_title">Date:</div>
896       <div class="header_age">
897         {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
898       </div>
899       <div id="header_commit_msg_title">Message:</div>
900       <div id="header_commit_msg">{{ rc->commit_msg }}</div>
901     </div>
902   </div>
903   <div class="dotted_line"></div>
904   <div id="blame">
905     {{ "\n" }}
906     {!
907         err = got_output_file_blame(c, &blame_line);
908         if (err) {
909                 log_warnx("%s: got_output_file_blame: %s", __func__,
910                     err->msg);
911                 return (-1);
912         }
913     !}
914   </div>
915 </div>
916 {{ end }}
918 {{ define blame_line(struct template *tp, const char *line,
919     struct blame_line *bline, int lprec, int lcur) }}
921         struct request          *c = tp->tp_arg;
922         struct transport        *t = c->t;
923         struct repo_dir         *repo_dir = t->repo_dir;
924         char                    *committer, *s;
925         struct gotweb_url        url = {
926                 .action = DIFF,
927                 .index_page = -1,
928                 .page = -1,
929                 .path = repo_dir->name,
930                 .commit = bline->id_str,
931         };
933         s = strchr(bline->committer, '<');
934         committer = s ? s + 1 : bline->committer;
936         s = strchr(committer, '@');
937         if (s)
938                 *s = '\0';
940 <div class="blame_wrapper">
941   <div class="blame_number">{{ printf "%.*d", lprec, lcur }}</div>
942   <div class="blame_hash">
943     <a href="{{ render gotweb_render_url(c, &url) }}">
944       {{ printf "%.8s", bline->id_str }}
945     </a>
946   </div>
947   <div class="blame_date">{{ bline->datebuf }}</div>
948   <div class="blame_author">{{ printf "%.9s", committer }}</div>
949   <div class="blame_code">{{ line }}</div>
950 </div>
951 {{ end }}
953 {{ define gotweb_render_rss(struct template *tp) }}
955         struct request          *c = tp->tp_arg;
956         struct server           *srv = c->srv;
957         struct transport        *t = c->t;
958         struct repo_dir         *repo_dir = t->repo_dir;
959         struct repo_tag         *rt;
960         struct gotweb_url        summary = {
961                 .action = SUMMARY,
962                 .index_page = -1,
963                 .page = -1,
964                 .path = repo_dir->name,
965         };
967 <?xml version="1.0" encoding="UTF-8"?>
968 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
969   <channel>
970     <title>Tags of {{ repo_dir->name }}</title>
971     <link>
972       <![CDATA[
973         {{ render gotweb_render_absolute_url(c, &summary) }}
974       ]]>
975     </link>
976     {{ if srv->show_repo_description }}
977       <description>{{ repo_dir->description }}</description>
978     {{ end }}
979     {{ tailq-foreach rt &t->repo_tags entry }}
980       {{ render rss_tag_item(tp, rt) }}
981     {{ end }}
982   </channel>
983 </rss>
984 {{ end }}
986 {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
988         struct request          *c = tp->tp_arg;
989         struct transport        *t = c->t;
990         struct repo_dir         *repo_dir = t->repo_dir;
991         char                    *tag_name = rt->tag_name;
992         struct gotweb_url        tag = {
993                 .action = TAG,
994                 .index_page = -1,
995                 .page = -1,
996                 .path = repo_dir->name,
997                 .commit = rt->commit_id,
998         };
1000         if (strncmp(tag_name, "refs/tags/", 10) == 0)
1001                 tag_name += 10;
1003 <item>
1004   <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1005   <link>
1006     <![CDATA[
1007       {{ render gotweb_render_absolute_url(c, &tag) }}
1008     ]]>
1009   </link>
1010   <description>
1011     <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
1012   </description>
1013   {{ render rss_author(tp, rt->tagger) }}
1014   <guid isPermaLink="false">{{ rt->commit_id }}</guid>
1015   <pubDate>
1016     {{ render gotweb_render_age(tp, rt->tagger_time, TM_RFC822) }}
1017   </pubDate>
1018 </item>
1019 {{ end }}
1021 {{ define rss_author(struct template *tp, char *author) }}
1023         char    *t, *mail;
1025         /* what to do if the author name contains a paren? */
1026         if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
1027                 return 0;
1029         t = strchr(author, '<');
1030         if (t == NULL)
1031                 return 0;
1032         *t = '\0';
1033         mail = t+1;
1035         while (isspace((unsigned char)*--t))
1036                 *t = '\0';
1038         t = strchr(mail, '>');
1039         if (t == NULL)
1040                 return 0;
1041         *t = '\0';
1043 <author>
1044   {{ mail }} {{" "}} ({{ author }})
1045 </author>
1046 {{ end }}