aboutsummaryrefslogtreecommitdiff
path: root/ui-shared.c
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
Diffstat (limited to 'ui-shared.c')
-rw-r--r--ui-shared.c96
1 files changed, 90 insertions, 6 deletions
diff --git a/ui-shared.c b/ui-shared.c
index a6a828d..686fde0 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1,6 +1,14 @@
/* 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)
@@ -12,6 +20,7 @@
#include "ui-shared.h"
#include "cmd.h"
#include "html.h"
+#include "ui-ci.h"
#include "version.h"
static const char cgit_doctype[] =
@@ -342,6 +351,12 @@ 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)
{
@@ -761,6 +776,51 @@ 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='");
@@ -802,6 +862,27 @@ 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();
@@ -832,11 +913,12 @@ void cgit_print_docstart(void)
else
emit_js_link(NULL, "/cgit.js");
- if (ctx.cfg.favicon && *ctx.cfg.favicon) {
- html("<link rel='shortcut icon' href='");
- html_attr(ctx.cfg.favicon);
- html("'/>\n");
- }
+ 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 (host && ctx.repo && ctx.qry.head) {
char *fileurl;
struct strbuf sb = STRBUF_INIT;
@@ -877,7 +959,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://git.zx2c4.com/cgit/about/'>cgit %s</a> "
+ htmlf("<div class='footer'>generated by <a href='https://sayag.it/cgitext.git/about/'>cgitext %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");
@@ -1110,6 +1192,8 @@ 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);