X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/db4b735464aa9a3a329494b7f042413a65e182f2..7511f4b4df521656d422010b06e2b5b96b21eb84:/ui-shared.c diff --git a/ui-shared.c b/ui-shared.c index f8e5bef..23a893b 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -11,7 +11,7 @@ #include "cmd.h" #include "html.h" -const char cgit_doctype[] = +static const char cgit_doctype[] = "\n"; @@ -46,7 +46,7 @@ void cgit_vprint_error(const char *fmt, va_list ap) html("\n"); } -const char *cgit_httpscheme() +const char *cgit_httpscheme(void) { if (ctx.env.https && !strcmp(ctx.env.https, "on")) return "https://"; @@ -54,7 +54,7 @@ const char *cgit_httpscheme() return "http://"; } -const char *cgit_hosturl() +const char *cgit_hosturl(void) { if (ctx.env.http_host) return ctx.env.http_host; @@ -65,7 +65,18 @@ const char *cgit_hosturl() return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port); } -const char *cgit_rooturl() +const char *cgit_currenturl(void) +{ + if (!ctx.qry.url) + return cgit_rooturl(); + const char *root = cgit_rooturl(); + size_t len = strlen(root); + if (len && root[len - 1] == '/') + return fmtalloc("%s%s", root, ctx.qry.url); + return fmtalloc("%s/%s", root, ctx.qry.url); +} + +const char *cgit_rooturl(void) { if (ctx.cfg.virtual_root) return ctx.cfg.virtual_root; @@ -73,9 +84,9 @@ const char *cgit_rooturl() return ctx.cfg.script_name; } -const char *cgit_loginurl() +const char *cgit_loginurl(void) { - static const char *login_url = 0; + static const char *login_url; if (!login_url) login_url = fmtalloc("%s?p=login", cgit_rooturl()); return login_url; @@ -112,7 +123,7 @@ char *cgit_fileurl(const char *reponame, const char *pagename, char *cgit_pageurl(const char *reponame, const char *pagename, const char *query) { - return cgit_fileurl(reponame, pagename, 0, query); + return cgit_fileurl(reponame, pagename, NULL, query); } const char *cgit_repobasename(const char *reponame) @@ -140,14 +151,14 @@ const char *cgit_repobasename(const char *reponame) return rvbuf; } -static void site_url(const char *page, const char *search, const char *sort, int ofs) +static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root) { char *delim = "?"; - if (!page) - html_attr(ctx.qry.url); - else + if (always_root || page) html_attr(cgit_rooturl()); + else + html_attr(cgit_currenturl()); if (page) { htmlf("?p=%s", page); @@ -172,7 +183,7 @@ static void site_url(const char *page, const char *search, const char *sort, int } static void site_link(const char *page, const char *name, const char *title, - const char *class, const char *search, const char *sort, int ofs) + const char *class, const char *search, const char *sort, int ofs, int always_root) { html(""); html_txt(name); html(""); } void cgit_index_link(const char *name, const char *title, const char *class, - const char *pattern, const char *sort, int ofs) + const char *pattern, const char *sort, int ofs, int always_root) { - site_link(NULL, name, title, class, pattern, sort, ofs); + site_link(NULL, name, title, class, pattern, sort, ofs, always_root); } static char *repolink(const char *title, const char *class, const char *page, @@ -439,7 +450,7 @@ static void cgit_self_link(char *name, const char *title, const char *class) { if (!strcmp(ctx.qry.page, "repolist")) cgit_index_link(name, title, class, ctx.qry.search, ctx.qry.sort, - ctx.qry.ofs); + ctx.qry.ofs, 1); else if (!strcmp(ctx.qry.page, "summary")) cgit_summary_link(name, title, class, ctx.qry.head); else if (!strcmp(ctx.qry.page, "tag")) @@ -728,7 +739,7 @@ void cgit_print_docstart(void) html_include(ctx.cfg.header); } -void cgit_print_docend() +void cgit_print_docend(void) { html(" \n"); if (ctx.cfg.embedded) { @@ -868,7 +879,7 @@ static void print_header(void) html(""); if (ctx.repo) { - cgit_index_link("index", NULL, NULL, NULL, NULL, 0); + cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1); html(" : "); cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); if (ctx.env.authenticated) { @@ -946,13 +957,13 @@ void cgit_print_pageheader(void) html("\n"); html("\n"); } else if (ctx.env.authenticated) { - site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0); + site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1); if (ctx.cfg.root_readme) site_link("about", "about", NULL, hc("about"), - NULL, NULL, 0); + NULL, NULL, 0, 1); html(""); html("
\n"); html("