blob: a2c018e3087b8b70866a55f2de4a110a81dddc90 [file] [log] [blame]
Lars Hjemli14180342006-12-11 16:55:07 +01001/* ui-summary.c: functions for generating repo summary page
2 *
3 * Copyright (C) 2006 Lars Hjemli
4 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9#include "cgit.h"
Lars Hjemlib1f9b9c2008-02-23 22:45:33 +010010#include "html.h"
Lars Hjemlic5984a92008-03-24 16:38:47 +010011#include "ui-log.h"
12#include "ui-refs.h"
Lars Hjemli14180342006-12-11 16:55:07 +010013
Lars Hjemli78af25c2008-07-27 11:54:06 +020014int urls = 0;
15
16static void print_url(char *base, char *suffix)
17{
18 if (!base || !*base)
19 return;
20 if (urls++ == 0) {
21 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
22 html("<tr><th class='left' colspan='4'>Clone</th></tr>\n");
23 }
24 if (suffix && *suffix)
25 base = fmt("%s/%s", base, suffix);
26 html("<tr><td colspan='4'><a href='");
Lars Hjemli0071aa82008-10-05 21:21:42 +020027 html_url_path(base);
Lars Hjemli78af25c2008-07-27 11:54:06 +020028 html("'>");
29 html_txt(base);
30 html("</a></td></tr>\n");
31}
32
33static void print_urls(char *txt, char *suffix)
34{
35 char *h = txt, *t, c;
36
37 while (h && *h) {
38 while (h && *h == ' ')
39 h++;
40 t = h;
41 while (t && *t && *t != ' ')
42 t++;
43 c = *t;
44 *t = 0;
45 print_url(h, suffix);
46 *t = c;
47 h = t;
48 }
49}
50
Lars Hjemlid14c5f62006-12-11 17:04:19 +010051void cgit_print_summary()
Lars Hjemli14180342006-12-11 16:55:07 +010052{
Lars Hjemli29154832007-11-11 13:04:28 +010053 html("<table summary='repository info' class='list nowrap'>");
Lars Hjemlib228d4f2008-02-16 13:07:13 +010054 cgit_print_branches(ctx.cfg.summary_branches);
Lars Hjemli23734c52007-01-17 01:10:39 +010055 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
Lars Hjemlib228d4f2008-02-16 13:07:13 +010056 cgit_print_tags(ctx.cfg.summary_tags);
Lars Hjemli5764fe92008-04-14 22:13:38 +020057 if (ctx.cfg.summary_log > 0) {
58 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
59 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
60 NULL, NULL, 0);
61 }
Lars Hjemli78af25c2008-07-27 11:54:06 +020062 if (ctx.repo->clone_url)
63 print_urls(ctx.repo->clone_url, NULL);
64 else if (ctx.cfg.clone_prefix)
65 print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
Lars Hjemli23734c52007-01-17 01:10:39 +010066 html("</table>");
Lars Hjemli14180342006-12-11 16:55:07 +010067}
Lars Hjemli90f64ad2008-04-28 23:06:57 +020068
Lars Hjemlie1782ff2009-08-09 11:50:34 +020069void cgit_print_repo_readme(char *path)
Lars Hjemli90f64ad2008-04-28 23:06:57 +020070{
Lars Hjemlie1782ff2009-08-09 11:50:34 +020071 char *slash, *tmp;
72
73 if (!ctx.repo->readme)
74 return;
75
76 if (path) {
77 slash = strrchr(ctx.repo->readme, '/');
78 if (!slash)
79 return;
80 tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1);
81 strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1);
82 strcpy(tmp + (slash - ctx.repo->readme + 1), path);
83 } else
84 tmp = ctx.repo->readme;
85 html("<div id='summary'>");
Lars Hjemli537c05f2009-08-09 13:27:21 +020086 if (ctx.repo->about_filter)
87 cgit_open_filter(ctx.repo->about_filter);
Lars Hjemlie1782ff2009-08-09 11:50:34 +020088 html_include(tmp);
Lars Hjemli537c05f2009-08-09 13:27:21 +020089 if (ctx.repo->about_filter)
90 cgit_close_filter(ctx.repo->about_filter);
Lars Hjemlie1782ff2009-08-09 11:50:34 +020091 html("</div>");
Lars Hjemli90f64ad2008-04-28 23:06:57 +020092}