ui-shared: Add current url helper function.

This commit is contained in:
Jason A. Donenfeld 2015-03-03 17:18:42 +01:00
parent db4b735464
commit 6bcda2f73d
3 changed files with 12 additions and 4 deletions

View File

@ -108,7 +108,7 @@ static int is_in_url(struct cgit_repo *repo)
static void print_sort_header(const char *title, const char *sort) static void print_sort_header(const char *title, const char *sort)
{ {
html("<th class='left'><a href='"); html("<th class='left'><a href='");
html_attr(ctx.qry.url); html_attr(cgit_currenturl());
htmlf("?s=%s", sort); htmlf("?s=%s", sort);
if (ctx.qry.search) { if (ctx.qry.search) {
html("&amp;q="); html("&amp;q=");
@ -315,7 +315,7 @@ void cgit_print_repolist()
cgit_close_filter(ctx.repo->owner_filter); cgit_close_filter(ctx.repo->owner_filter);
} else { } else {
html("<a href='"); html("<a href='");
html_attr(ctx.qry.url); html_attr(cgit_currenturl());
html("?q="); html("?q=");
html_url_arg(ctx.repo->owner); html_url_arg(ctx.repo->owner);
html("'>"); html("'>");

View File

@ -65,6 +65,13 @@ const char *cgit_hosturl()
return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port); return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port);
} }
const char *cgit_currenturl()
{
if (!ctx.qry.url)
return cgit_rooturl();
return ctx.qry.url;
}
const char *cgit_rooturl() const char *cgit_rooturl()
{ {
if (ctx.cfg.virtual_root) if (ctx.cfg.virtual_root)
@ -145,7 +152,7 @@ static void site_url(const char *page, const char *search, const char *sort, int
char *delim = "?"; char *delim = "?";
if (!page) if (!page)
html_attr(ctx.qry.url); html_attr(cgit_currenturl());
else else
html_attr(cgit_rooturl()); html_attr(cgit_rooturl());
@ -952,7 +959,7 @@ void cgit_print_pageheader(void)
NULL, NULL, 0); NULL, NULL, 0);
html("</td><td class='form'>"); html("</td><td class='form'>");
html("<form method='get' action='"); html("<form method='get' action='");
html_attr(ctx.qry.url); html_attr(cgit_currenturl());
html("'>\n"); html("'>\n");
html("<input type='text' name='q' size='10' value='"); html("<input type='text' name='q' size='10' value='");
html_attr(ctx.qry.search); html_attr(ctx.qry.search);

View File

@ -4,6 +4,7 @@
extern const char *cgit_httpscheme(); extern const char *cgit_httpscheme();
extern const char *cgit_hosturl(); extern const char *cgit_hosturl();
extern const char *cgit_rooturl(); extern const char *cgit_rooturl();
extern const char *cgit_currenturl();
extern const char *cgit_loginurl(); extern const char *cgit_loginurl();
extern char *cgit_repourl(const char *reponame); extern char *cgit_repourl(const char *reponame);
extern char *cgit_fileurl(const char *reponame, const char *pagename, extern char *cgit_fileurl(const char *reponame, const char *pagename,