Author: Lars Hjemli <hjemli@gmail.com>
Add cgit_index_link() function with support for offset This function will be used to build a pager in ui-repolist. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
ui-shared.c | 22 +++++++++++++++++----- ui-shared.h | 2 ++
diff --git a/ui-shared.c b/ui-shared.c index d08ede90b8125a63d1b553c8c78b02e18dd133e8..f36635495b7fdb2671af6ba949b31e9a9b4cdd8c 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -114,7 +114,7 @@ else 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 = "?"; @@ -133,11 +133,16 @@ 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) + char *search, int ofs) { html("<a"); if (title) { @@ -151,10 +156,16 @@ html_attr(class); 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, @@ -596,9 +607,10 @@ html("'/>\n"); 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()); diff --git a/ui-shared.h b/ui-shared.h index 76c2b1fd232a8bd566fa4d141c121933312a48a8..3005d305d41a3bf916e63093a61d4589a8399c10 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -7,6 +7,8 @@ const char *filename, const char *query); extern char *cgit_pageurl(const char *reponame, const char *pagename, const char *query); +extern void cgit_index_link(char *name, char *title, char *class, + char *pattern, int ofs); extern void cgit_tree_link(char *name, char *title, char *class, char *head, char *rev, char *path); extern void cgit_log_link(char *name, char *title, char *class, char *head,