commit b4c0bd7275f121f6250964ddfdf8db160ad486df from: Omar Polo date: Sat Dec 17 08:30:00 2022 UTC gotwebd: templateify gotweb_render_navs ok tracey@ commit - 03f6a843c825ee4566446557cfa33bd1ebb1827b commit + b4c0bd7275f121f6250964ddfdf8db160ad486df blob - 2edd61056bd5e9810fd5939e2e83708865ba7ce5 blob + 11f9c0394c8740b1306c0b3f5747079bbc1ad448 --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -98,8 +98,6 @@ static const struct got_error *gotweb_render_tag(struc static const struct got_error *gotweb_render_tags(struct request *); static const struct got_error *gotweb_render_tree(struct request *); static const struct got_error *gotweb_render_branches(struct request *); - -const struct got_error *gotweb_render_navs(struct request *); static void gotweb_free_querystring(struct querystring *); static void gotweb_free_repo_dir(struct repo_dir *); @@ -660,35 +658,42 @@ gotweb_render_content_type_file(struct request *c, con return NULL; } -const struct got_error * -gotweb_render_navs(struct request *c) +void +gotweb_get_navs(struct request *c, struct gotweb_url *prev, int *have_prev, + struct gotweb_url *next, int *have_next) { - const struct got_error *error = NULL; struct transport *t = c->t; struct querystring *qs = t->qs; struct server *srv = c->srv; - int r; - r = fcgi_printf(c, "
\n\n" /* #nav_prev */ - "\n"); /* #nav_next */ - fcgi_printf(c, "
\n"); /* #np_wrapper */ -done: - free(t->next_id); - t->next_id = NULL; - free(t->prev_id); - t->prev_id = NULL; - return error; } static const struct got_error * @@ -906,8 +863,7 @@ gotweb_render_index(struct request *c) t->repos_total <= srv->max_repos_display) goto done; - error = gotweb_render_navs(c); - if (error) + if (gotweb_render_navs(c->tp) == -1) goto done; done: if (sd_dent) { @@ -1066,8 +1022,7 @@ gotweb_render_commits(struct request *c) } if (t->next_id || t->prev_id) { - error = gotweb_render_navs(c); - if (error) + if (gotweb_render_navs(c->tp) == -1) goto done; } fcgi_printf(c, "\n"); /* .commits_content */ @@ -1603,8 +1558,7 @@ gotweb_render_tags(struct request *c) msg = NULL; } if (t->next_id || t->prev_id) { - error = gotweb_render_navs(c); - if (error) + if (gotweb_render_navs(c->tp) == -1) goto done; } fcgi_printf(c, "\n"); /* #tags_content */ blob - db15603fe2e34e9c6f0b3d4a599e93a5777bfd72 blob + ca24af3793aac515e3a3c00a8b6bcfc8e32cb5e8 --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -434,6 +434,8 @@ const struct got_error *gotweb_render_content_type(str const uint8_t *); const struct got_error *gotweb_render_content_type_file(struct request *, const uint8_t *, char *); +void gotweb_get_navs(struct request *, struct gotweb_url *, int *, + struct gotweb_url *, int *); const struct got_error *gotweb_get_time_str(char **, time_t, int); const struct got_error *gotweb_init_transport(struct transport **); const struct got_error *gotweb_escape_html(char **, const char *); @@ -453,6 +455,7 @@ int gotweb_render_footer(struct template *); int gotweb_render_repo_table_hdr(struct template *); int gotweb_render_repo_fragment(struct template *, struct repo_dir *); int gotweb_render_briefs(struct template *); +int gotweb_render_navs(struct template *); /* parse.y */ int parse_config(const char *, struct gotwebd *); blob - 0d49898e174e9bfad77b158729eb04ab949bd736 blob + 88158c157c6d585b1e9692319e29e9bbe08f9390 --- gotwebd/pages.tmpl +++ gotwebd/pages.tmpl @@ -29,8 +29,6 @@ #include "gotwebd.h" #include "tmpl.h" - -const struct got_error *gotweb_render_navs(struct request *); static int gotweb_render_age(struct template *tp, time_t time, int ref_tm) @@ -296,7 +294,41 @@ gotweb_render_age(struct template *tp, time_t time, in
{{ end }} {{ if t->next_id || t->prev_id }} - {! gotweb_render_navs(c); !} + {{ render gotweb_render_navs(tp) }} {{ end }} + +{{ end }} + +{{ define gotweb_render_navs(struct template *tp) }} +{! + struct request *c = tp->tp_arg; + struct transport *t = c->t; + struct gotweb_url prev, next; + int have_prev, have_next; + + gotweb_get_navs(c, &prev, &have_prev, &next, &have_next); +!} +
+ +
+{{ finally }} +{! + free(t->next_id); + t->next_id = NULL; + free(t->prev_id); + t->prev_id = NULL; +!} {{ end }}