config: make empty js= omit script tag
[cgit.git] / ui-summary.c
blob947812a814caff74bab85079ab7559640d7f5753
1 /* ui-summary.c: functions for generating repo summary page
3 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
9 #include "cgit.h"
10 #include "ui-summary.h"
11 #include "html.h"
12 #include "ui-blob.h"
13 #include "ui-log.h"
14 #include "ui-plain.h"
15 #include "ui-refs.h"
16 #include "ui-shared.h"
18 static int urls;
20 static void print_url(const char *url)
22 int columns = 3;
24 if (ctx.repo->enable_log_filecount)
25 columns++;
26 if (ctx.repo->enable_log_linecount)
27 columns++;
29 if (urls++ == 0) {
30 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
31 htmlf("<tr class='nohover'><th class='left' colspan='%d'>Clone</th></tr>\n", columns);
34 htmlf("<tr><td colspan='%d'><a rel='vcs-git' href='", columns);
35 html_url_path(url);
36 html("' title='");
37 html_attr(ctx.repo->name);
38 html(" Git repository'>");
39 html_txt(url);
40 html("</a></td></tr>\n");
43 void cgit_print_summary(void)
45 int columns = 3;
47 if (ctx.repo->enable_log_filecount)
48 columns++;
49 if (ctx.repo->enable_log_linecount)
50 columns++;
52 cgit_print_layout_start();
53 html("<table summary='repository info' class='list nowrap'>");
54 cgit_print_branches(ctx.cfg.summary_branches);
55 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
56 cgit_print_tags(ctx.cfg.summary_tags);
57 if (ctx.cfg.summary_log > 0) {
58 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
59 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
60 NULL, NULL, 0, 0, 0);
62 urls = 0;
63 cgit_add_clone_urls(print_url);
64 html("</table>");
65 cgit_print_layout_end();
68 /* The caller must free the return value. */
69 static char* append_readme_path(const char *filename, const char *ref, const char *path)
71 char *file, *base_dir, *full_path, *resolved_base = NULL, *resolved_full = NULL;
72 /* If a subpath is specified for the about page, make it relative
73 * to the directory containing the configured readme. */
75 file = xstrdup(filename);
76 base_dir = dirname(file);
77 if (!strcmp(base_dir, ".") || !strcmp(base_dir, "..")) {
78 if (!ref) {
79 free(file);
80 return NULL;
82 full_path = xstrdup(path);
83 } else
84 full_path = fmtalloc("%s/%s", base_dir, path);
86 if (!ref) {
87 resolved_base = realpath(base_dir, NULL);
88 resolved_full = realpath(full_path, NULL);
89 if (!resolved_base || !resolved_full || !starts_with(resolved_full, resolved_base)) {
90 free(full_path);
91 full_path = NULL;
95 free(file);
96 free(resolved_base);
97 free(resolved_full);
99 return full_path;
102 void cgit_print_repo_readme(const char *path)
104 char *filename, *ref, *mimetype;
105 int free_filename = 0;
107 mimetype = get_mimetype_for_filename(path);
108 if (mimetype && (!strncmp(mimetype, "image/", 6) || !strncmp(mimetype, "video/", 6))) {
109 ctx.page.mimetype = mimetype;
110 ctx.page.charset = NULL;
111 cgit_print_plain();
112 free(mimetype);
113 return;
115 free(mimetype);
117 cgit_print_layout_start();
118 if (ctx.repo->readme.nr == 0)
119 goto done;
121 filename = ctx.repo->readme.items[0].string;
122 ref = ctx.repo->readme.items[0].util;
124 if (path) {
125 free_filename = 1;
126 filename = append_readme_path(filename, ref, path);
127 if (!filename)
128 goto done;
131 /* Print the calculated readme, either from the git repo or from the
132 * filesystem, while applying the about-filter.
134 html("<div id='summary'>");
135 cgit_open_filter(ctx.repo->about_filter, filename);
136 if (ref)
137 cgit_print_file(filename, ref, 1);
138 else
139 html_include(filename);
140 cgit_close_filter(ctx.repo->about_filter);
142 html("</div>");
143 if (free_filename)
144 free(filename);
146 done:
147 cgit_print_layout_end();