commit 6da1aa18fd7de5e62a0e02b4739909a73eab9f42 from: Omar Polo via: Thomas Adam date: Fri Dec 01 17:01:41 2023 UTC gotwebd: add breadcums to navigate the tree/blob views ok tracey@ commit - 277fd65e2e0aa43e43b56464bc53be08282ecca2 commit + 6da1aa18fd7de5e62a0e02b4739909a73eab9f42 blob - 5f47afc1244ea03fcd8d649bf7f9ea71e13cea9c blob + 5de661cded74918826aa456f1e1036d8a1ab62de --- gotwebd/pages.tmpl +++ gotwebd/pages.tmpl @@ -42,6 +42,7 @@ enum gotweb_ref_tm { TM_LONG, }; +static int breadcumbs(struct template *); static int datetime(struct template *, time_t, int); static int gotweb_render_blob_line(struct template *, const char *, size_t); static int gotweb_render_tree_item(struct template *, struct got_tree_entry *); @@ -56,6 +57,23 @@ static inline int branch(struct template *, struct got static inline int rss_tag_item(struct template *, struct repo_tag *); static inline int rss_author(struct template *, char *); +static inline char * +nextsep(char *s, char **t) +{ + char *q; + + while (*s == '/') + s++; + *t = s; + if (*s == '\0') + return NULL; + + q = strchr(s, '/'); + if (q == NULL) + q = strchr(s, '\0'); + return q; +} + !} {{ define datetime(struct template *tp, time_t t, int fmt) }} @@ -82,6 +100,59 @@ static inline int rss_author(struct template *, char * {{ end }} +{{ define breadcumbs(struct template *tp) }} +{! + struct request *c = tp->tp_arg; + struct querystring *qs = c->t->qs; + struct gotweb_url url; + const char *folder = qs->folder; + char *t, *s = NULL, *dir = NULL; + char ch; + + memset(&url, 0, sizeof(url)); + url.index_page = -1; + url.page = -1; + url.action = TREE; + url.path = qs->path; + url.commit = qs->commit; + + if (folder && *folder != '\0') { + while (*folder == '/') + folder++; + dir = strdup(folder); + if (dir == NULL) + return (-1); + s = dir; + } +!} + {{ " / " }} + tree + {{ " / " }} + {{ if dir }} + {{ while (s = nextsep(s, &t)) != NULL }} + {! + ch = *s; + *s = '\0'; + url.folder = dir; + !} + + + {{ t }} + + {{ " / " }} + + {! *s = ch; !} + {{ end }} + {{ end }} + + {{ if qs->file }} + {{ qs->file }} + {{ end}} + + {{ finally }} + {! free(dir); !} +{{ end }} + {{ define gotweb_render_page(struct template *tp, int (*body)(struct template *)) }} {! @@ -132,7 +203,9 @@ static inline int rss_author(struct template *, char * {{ qs->path }} {{ end }} - {{ if qs->action != INDEX }} + {{ if qs->action == TREE || qs->action == BLOB }} + {{ render breadcumbs(tp) }} + {{ else if qs->action != INDEX }} {{ " / " }}{{ gotweb_action_name(qs->action) }} {{ end }}