Diffstat (limited to 'ui-shared.c')
| -rw-r--r-- | ui-shared.c | 154 |
1 files changed, 16 insertions, 138 deletions
diff --git a/ui-shared.c b/ui-shared.c index 9eb48a9..d5b5b20 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1,26 +1,15 @@ /* ui-shared.c: common web output functions * * Copyright (C) 2006-2017 cgit Development Team <cgit@lists.zx2c4.com> - * Copyright (C) 2026 Saya Andy <saya.andy@posteo.com> - * - * Modified 2026 by Saya Andy: - * Implement ci link tab - * Check repo existence - * Replace memrchr() for macOS compatibility - * Allow multiple favicons of different mime types to be used - * Include favicon.svg as default * * Licensed under GNU General Public License v2 * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-shared.h" #include "cmd.h" #include "html.h" -#include "ui-ci.h" #include "version.h" static const char cgit_doctype[] = @@ -351,12 +340,6 @@ void cgit_tag_link(const char *name, const char *title, const char *class, reporevlink("tag", name, title, class, tag, NULL, NULL); } -void cgit_ci_link(const char *name, const char *title, const char *class, - const char *head) -{ - reporevlink("ci", name, title, class, head, NULL, NULL); -} - void cgit_tree_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path) { @@ -494,21 +477,6 @@ void cgit_diff_link(const char *name, const char *title, const char *class, html_url_arg(old_rev); delim = "&"; } - /* - * Emit the ref offsets after the refs so that they follow the - * refs through file-level links; a zero offset means the ref - * itself. - */ - if (ctx.qry.idoff) { - html(delim); - htmlf("idoff=%d", ctx.qry.idoff); - delim = "&"; - } - if (ctx.qry.id2off) { - html(delim); - htmlf("id2off=%d", ctx.qry.id2off); - delim = "&"; - } if (ctx.qry.difftype) { html(delim); htmlf("dt=%d", ctx.qry.difftype); @@ -791,51 +759,6 @@ void cgit_redirect(const char *url, bool permanent) html("\n\n"); } -static const struct { - const char *ext; - const char *mimetype; -} favicon_mimetypes[] = { - { "ico", "image/x-icon" }, - { "png", "image/png" }, - { "svg", "image/svg+xml" }, - { "gif", "image/gif" }, - { "jpg", "image/jpeg" }, - { "jpeg", "image/jpeg" }, - { "webp", "image/webp" }, - { "avif", "image/avif" }, -}; - -/* Deduce the mimetype of a favicon from the extension of its url, ignoring - * any query string or fragment. Returns NULL for unknown extensions. - */ -static const char *favicon_mimetype(const char *url) -{ - const char *p, *end, *ext = NULL; - size_t len; - int i; - - end = strpbrk(url, "?#"); - if (!end) - end = url + strlen(url); - - for (p = url; p < end; p++) { - if (*p == '/') - ext = NULL; - else if (*p == '.') - ext = p + 1; - } - if (!ext) - return NULL; - len = end - ext; - - for (i = 0; i < ARRAY_SIZE(favicon_mimetypes); i++) { - if (strlen(favicon_mimetypes[i].ext) == len && - !strncasecmp(favicon_mimetypes[i].ext, ext, len)) - return favicon_mimetypes[i].mimetype; - } - return NULL; -} - static void print_rel_vcs_link(const char *url) { html("<link rel='vcs-git' href='"); @@ -877,27 +800,6 @@ static int emit_js_link(struct string_list_item *s, void *arg) return 0; } -static int emit_favicon_link(struct string_list_item *s, void *arg) -{ - const char *url = s ? s->string : (const char *)arg; - const char *mimetype; - - /* Do not emit anything if favicon= is specified. */ - if (!*url) - return 0; - - html("<link rel='shortcut icon' href='"); - html_attr(url); - mimetype = favicon_mimetype(url); - if (mimetype) { - html("' type='"); - html_attr(mimetype); - } - html("'/>\n"); - - return 0; -} - void cgit_print_docstart(void) { char *host = cgit_hosturl(); @@ -928,12 +830,11 @@ void cgit_print_docstart(void) else emit_js_link(NULL, "/cgit.js"); - if (ctx.cfg.favicon.items) - for_each_string_list(&ctx.cfg.favicon, emit_favicon_link, NULL); - else - emit_favicon_link(NULL, "/favicon.svg"); - emit_favicon_link(NULL, "/favicon.ico"); - + if (ctx.cfg.favicon) { + html("<link rel='shortcut icon' href='"); + html_attr(ctx.cfg.favicon); + html("'/>\n"); + } if (host && ctx.repo && ctx.qry.head) { char *fileurl; struct strbuf sb = STRBUF_INIT; @@ -974,7 +875,7 @@ void cgit_print_docend(void) if (ctx.cfg.footer) html_include(ctx.cfg.footer); else { - htmlf("<div class='footer'>generated by <a href='https://sayag.it/cgitext.git/about/'>cgitext %s</a> " + htmlf("<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit %s</a> " "(<a href='https://git-scm.com/'>git %s</a>) at ", cgit_version, git_version_string); html_txt(show_date(time(NULL), 0, cgit_date_mode(DATE_ISO8601))); html("</div>\n"); @@ -986,18 +887,13 @@ void cgit_print_docend(void) void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) { va_list ap; - va_start(ap, fmt); - cgit_vprint_error_page(code, msg, fmt, ap); - va_end(ap); -} - -void cgit_vprint_error_page(int code, const char *msg, const char *fmt, va_list ap) -{ ctx.page.expires = ctx.cfg.cache_dynamic_ttl; ctx.page.status = code; ctx.page.statusmsg = msg; cgit_print_layout_start(); + va_start(ap, fmt); cgit_vprint_error(fmt, ap); + va_end(ap); cgit_print_layout_end(); } @@ -1038,9 +934,10 @@ void cgit_add_clone_urls(void (*fn)(const char *)) add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url); } -static int print_branch_option(const struct reference *ref, void *cb_data) +static int print_branch_option(const char *refname, const struct object_id *oid, + int flags, void *cb_data) { - char *name = (char *)ref->name; + char *name = (char *)refname; html_option(name, name, ctx.qry.head); return 0; } @@ -1066,10 +963,6 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search, html_hidden("id", ctx.qry.oid); if (ctx.qry.oid2) html_hidden("id2", ctx.qry.oid2); - if (ctx.qry.idoff) - html_hidden("idoff", fmt("%d", ctx.qry.idoff)); - if (ctx.qry.id2off) - html_hidden("id2off", fmt("%d", ctx.qry.id2off)); if (ctx.qry.showmsg) html_hidden("showmsg", "1"); @@ -1143,16 +1036,14 @@ static void print_header(void) cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1); html(" : "); cgit_summary_link(ctx.repo->name, NULL, NULL, NULL); - if (ctx.env.authenticated && cgit_have_repository()) { + if (ctx.env.authenticated) { html("</td><td class='form'>"); html("<form method='get'>\n"); cgit_add_hidden_formfields(0, 1, ctx.qry.page); html("<select name='h' onchange='this.form.submit();'>\n"); - refs_for_each_branch_ref(get_main_ref_store(the_repository), - print_branch_option, ctx.qry.head); + for_each_branch_ref(print_branch_option, ctx.qry.head); if (ctx.repo->enable_remote_branches) - refs_for_each_remote_ref(get_main_ref_store(the_repository), - print_branch_option, ctx.qry.head); + for_each_remote_ref(print_branch_option, ctx.qry.head); html("</select> "); html("<input type='submit' value='switch'/>"); html("</form>"); @@ -1211,8 +1102,6 @@ void cgit_print_pageheader(void) if (ctx.repo->max_stats) cgit_stats_link("stats", NULL, hc("stats"), ctx.qry.head, ctx.qry.vpath); - if (cgit_ci_available()) - cgit_ci_link("ci", NULL, hc("ci"), ctx.qry.head); if (ctx.repo->homepage) { html("<a href='"); html_attr(ctx.repo->homepage); @@ -1261,7 +1150,7 @@ void cgit_print_pageheader(void) html("<div class='path'>"); html("path: "); cgit_print_path_crumbs(ctx.qry.vpath); - if (ctx.repo->enable_follow_links && !strcmp(ctx.qry.page, "log")) { + if (ctx.cfg.enable_follow_links && !strcmp(ctx.qry.page, "log")) { html(" ("); ctx.qry.follow = !ctx.qry.follow; cgit_self_link(ctx.qry.follow ? "follow" : "unfollow", @@ -1350,17 +1239,6 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, strbuf_release(&filename); } -/* Locate the last '/' within the first len bytes of path, or NULL if - * there is none. Avoids memrchr(), which is a GNU extension. - */ -static const char *find_last_slash(const char *path, size_t len) -{ - while (len > 0) - if (path[--len] == '/') - return path + len; - return NULL; -} - void cgit_set_title_from_path(const char *path) { struct strbuf sb = STRBUF_INIT; @@ -1369,7 +1247,7 @@ void cgit_set_title_from_path(const char *path) if (!path) return; - for (last_slash = path + strlen(path); (slash = find_last_slash(path, last_slash - path)) != NULL; last_slash = slash) { + for (last_slash = path + strlen(path); (slash = memrchr(path, '/', last_slash - path)) != NULL; last_slash = slash) { strbuf_add(&sb, slash + 1, last_slash - slash - 1); strbuf_addstr(&sb, " \xc2\xab "); } |