X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/b88fb016d0209f7041ac7d3b4d2c077318407a4d..17890d0058c1555133c8767ceb123e809e6971ab:/ui-shared.c diff --git a/ui-shared.c b/ui-shared.c index cc1ab8b..cd98387 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -7,6 +7,8 @@ */ #include "cgit.h" +#include "cmd.h" +#include "html.h" const char cgit_doctype[] = "tm_hour, tm->tm_min, tm->tm_sec); } -static long ttl_seconds(long ttl) -{ - if (ttl<0) - return 60 * 60 * 24 * 365; - else - return ttl * 60; -} - void cgit_print_error(char *msg) { html("
"); @@ -120,6 +114,60 @@ char *cgit_currurl() return fmt("%s/", ctx.cfg.virtual_root); } +static void site_url(char *page, char *search, int ofs) +{ + char *delim = "?"; + + if (ctx.cfg.virtual_root) { + html_attr(ctx.cfg.virtual_root); + if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') + html("/"); + } else + html(ctx.cfg.script_name); + + if (page) { + htmlf("?p=%s", page); + delim = "&"; + } + if (search) { + 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, int ofs) +{ + html(""); + html_txt(name); + html(""); +} + +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) { @@ -360,24 +408,34 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) secs * 1.0 / TM_YEAR); } -void cgit_print_docstart(char *title, struct cacheitem *item) +void cgit_print_http_headers(struct cgit_context *ctx) { - html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); - htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); - htmlf("Expires: %s\n", http_date(item->st.st_mtime + - ttl_seconds(item->ttl))); + if (ctx->page.mimetype && ctx->page.charset) + htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, + ctx->page.charset); + else if (ctx->page.mimetype) + htmlf("Content-Type: %s\n", ctx->page.mimetype); + if (ctx->page.filename) + htmlf("Content-Disposition: inline; filename=\"%s\"\n", + ctx->page.filename); + htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); + htmlf("Expires: %s\n", http_date(ctx->page.expires)); html("\n"); +} + +void cgit_print_docstart(struct cgit_context *ctx) +{ html(cgit_doctype); html("\n"); html("\n"); html(""); - html_txt(title); + html_txt(ctx->page.title); html("\n"); htmlf("\n", cgit_version); - if (ctx.cfg.robots && *ctx.cfg.robots) - htmlf("\n", ctx.cfg.robots); + if (ctx->cfg.robots && *ctx->cfg.robots) + htmlf("\n", ctx->cfg.robots); html("\n"); html("\n"); html("\n"); @@ -385,7 +443,10 @@ void cgit_print_docstart(char *title, struct cacheitem *item) void cgit_print_docend() { - html("\n\n\n\n\n"); + html("
\n\n\n"); } int print_branch_option(const char *refname, const unsigned char *sha1, @@ -462,109 +523,139 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page) } } -void cgit_print_pageheader(char *title, int show_search) +char *hc(struct cgit_cmd *cmd, const char *page) { - static const char *default_info = "This is cgit, a fast webinterface for git repositories"; - int header = 0; - char *url; + return (strcmp(cmd->name, page) ? NULL : "active"); +} - html("\n"); - html("