html("</div>\n");
}
+char *cgit_hosturl()
+{
+ char *host, *port;
+
+ host = getenv("SERVER_NAME");
+ if (!host)
+ return NULL;
+ port = getenv("SERVER_PORT");
+ if (port && atoi(port) != 80)
+ host = xstrdup(fmt("%s:%d", host, atoi(port)));
+ else
+ host = xstrdup(host);
+ return host;
+}
+
char *cgit_rooturl()
{
if (ctx.cfg.virtual_root)
return fmt("%s/", ctx.cfg.virtual_root);
}
-static void site_url(char *page, char *search)
+static void site_url(char *page, char *search, int ofs)
{
char *delim = "?";
html(delim);
html("q=");
html_attr(search);
+ delim = "&";
+ }
+ if (ofs) {
+ html(delim);
+ htmlf("ofs=%d", ofs);
}
}
static void site_link(char *page, char *name, char *title, char *class,
- char *search)
+ char *search, int ofs)
{
html("<a");
if (title) {
html("'");
}
html(" href='");
- site_url(page, search);
+ site_url(page, search, ofs);
html("'>");
html_txt(name);
html("</a>");
}
+void cgit_index_link(char *name, char *title, char *class, char *pattern,
+ int ofs)
+{
+ site_link(NULL, name, title, class, pattern, ofs);
+}
+
static char *repolink(char *title, char *class, char *page, char *head,
char *path)
{
html_link_close();
}
-void cgit_print_date(time_t secs, char *format)
+void cgit_print_date(time_t secs, char *format, int local_time)
{
char buf[64];
struct tm *time;
if (!secs)
return;
- time = gmtime(&secs);
+ if(local_time)
+ time = localtime(&secs);
+ else
+ time = gmtime(&secs);
strftime(buf, sizeof(buf)-1, format, time);
html_txt(buf);
}
secs = now - t;
if (secs > max_relative && max_relative >= 0) {
- cgit_print_date(t, format);
+ cgit_print_date(t, format, ctx.cfg.local_time);
return;
}
void cgit_print_docstart(struct cgit_context *ctx)
{
+ char *host = cgit_hosturl();
html(cgit_doctype);
html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
html("<head>\n");
html("<link rel='stylesheet' type='text/css' href='");
html_attr(ctx->cfg.css);
html("'/>\n");
+ if (ctx->cfg.favicon) {
+ html("<link rel='shortcut icon' href='");
+ html_attr(ctx->cfg.favicon);
+ html("'/>\n");
+ }
+ if (host && ctx->repo) {
+ html("<link rel='alternate' title='Atom feed' href='http://");
+ html_attr(cgit_hosturl());
+ html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path,
+ fmt("h=%s", ctx->qry.head)));
+ html("' type='application/atom+xml'/>");
+ }
html("</head>\n");
html("<body>\n");
}
void cgit_print_docend()
{
- html("</div>\n</body>\n</html>\n");
+ html("</div>");
+ if (ctx.cfg.footer)
+ html_include(ctx.cfg.footer);
+ else {
+ html("<div class='footer'>generated ");
+ cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
+ htmlf(" by cgit %s", cgit_version);
+ html("</div>\n");
+ }
+ html("</body>\n</html>\n");
}
int print_branch_option(const char *refname, const unsigned char *sha1,
html_hidden("url", url);
}
- if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch))
+ if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
+ strcmp(ctx.qry.head, ctx.repo->defbranch))
html_hidden("h", ctx.qry.head);
if (ctx.qry.sha1)
html("<td class='main'>");
if (ctx->repo) {
+ cgit_index_link("index", NULL, NULL, NULL, 0);
+ html(" : ");
reporevlink(NULL, ctx->repo->name, NULL, hc(cmd, "summary"),
ctx->qry.head, NULL, NULL);
- html(" : ");
- html_txt(ctx->qry.page);
html("</td><td class='form'>");
html("<form method='get' action=''>\n");
add_hidden_formfields(0, 1, ctx->qry.page);
html_txt(ctx->cfg.root_title);
html("</td></tr>\n");
- html("<tr><td class='sub'");
+ html("<tr><td class='sub'>");
if (ctx->repo) {
- html(" colspan='2'>");
html_txt(ctx->repo->desc);
+ html("</td><td class='sub right'>");
+ html_txt(ctx->repo->owner);
} else {
- html(">");
if (ctx->cfg.root_desc)
html_txt(ctx->cfg.root_desc);
else if (ctx->cfg.index_info)
html("<input type='submit' value='search'/>\n");
html("</form>\n");
} else {
- site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL);
+ site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0);
if (ctx->cfg.root_readme)
- site_link("about", "about", NULL, hc(cmd, "about"), NULL);
+ site_link("about", "about", NULL, hc(cmd, "about"),
+ NULL, 0);
html("</td><td class='form'>");
html("<form method='get' action='");
html_attr(cgit_rooturl());