summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMehmet Samet Duman <froster12@naver.com>2026-02-13 15:16:12 +0300
committerMehmet Samet Duman <froster12@naver.com>2026-02-13 15:16:12 +0300
commit4ce807b14cde82df10e0c63220a5b1b73610d7d2 (patch)
tree3e7192807778d06fe987e9eb40486f7555251ddb
parentbcd195b23999d238298140a2e76d5e3062d17b38 (diff)
downloadProject-Tick-4ce807b14cde82df10e0c63220a5b1b73610d7d2.tar.gz
Project-Tick-4ce807b14cde82df10e0c63220a5b1b73610d7d2.zip
feat: add support for multiple root external links configuration
Signed-off-by: Mehmet Samet Duman <froster12@naver.com>
-rw-r--r--cgit.c22
-rw-r--r--cgit.h1
-rw-r--r--cgitrc.5.txt18
-rwxr-xr-xtests/setup.sh5
-rw-r--r--tests/t0114-root-homepage.sh18
-rw-r--r--ui-shared.c25
6 files changed, 69 insertions, 20 deletions
diff --git a/cgit.c b/cgit.c
index 4479adcb78..feaa8b6803 100644
--- a/cgit.c
+++ b/cgit.c
@@ -40,6 +40,26 @@ static void add_mimetype(const char *name, const char *value)
item->util = xstrdup(value);
}
+static void add_root_link(const char *value)
+{
+ const char *sep;
+ struct string_list_item *item;
+
+ if (!value || !value[0])
+ return;
+
+ sep = strchr(value, '|');
+ if (sep && sep > value && sep[1]) {
+ item = string_list_append(&ctx.cfg.root_links,
+ xstrndup(value, sep - value));
+ item->util = xstrdup(sep + 1);
+ return;
+ }
+
+ item = string_list_append(&ctx.cfg.root_links, xstrdup(value));
+ item->util = xstrdup(value);
+}
+
static void process_cached_repolist(const char *path);
static void repo_config(struct cgit_repo *repo, const char *name, const char *value)
@@ -167,6 +187,8 @@ static void config_cb(const char *name, const char *value)
ctx.cfg.root_homepage = xstrdup(value);
else if (!strcmp(name, "root-homepage-title"))
ctx.cfg.root_homepage_title = xstrdup(value);
+ else if (!strcmp(name, "root-link"))
+ add_root_link(value);
else if (!strcmp(name, "css"))
string_list_append(&ctx.cfg.css, xstrdup(value));
else if (!strcmp(name, "js"))
diff --git a/cgit.h b/cgit.h
index 8d20e24880..b7b95e0f08 100644
--- a/cgit.h
+++ b/cgit.h
@@ -215,6 +215,7 @@ struct cgit_config {
char *project_list;
struct string_list readme;
struct string_list css;
+ struct string_list root_links;
char *robots;
char *root_title;
char *root_desc;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 53bba3e3ff..a7d4c8c64b 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -392,11 +392,18 @@ root-cla::
root-homepage::
Specifies an external URL to be shown as a link on the repository
- index page tabs (next to "index", "about", etc). Default value: none.
+ index page tabs (next to "index", "about", etc). This is kept for
+ backward compatibility; for multiple links use "root-link". Default
+ value: none.
root-homepage-title::
- Text to use for the root-homepage link label. Default value:
- "homepage".
+ Text to use for the root-homepage link label. This only applies to
+ "root-homepage". Default value: "homepage".
+
+root-link::
+ Add a root-level external link. This setting may be specified
+ multiple times. Value format is either "LABEL|URL" or "URL". When
+ only URL is given, the URL is used as link text.
root-title::
Text printed as heading on the repository index page. Default value:
@@ -930,8 +937,9 @@ root-desc=tracking the foobar development
root-readme=/var/www/htdocs/about.html
root-coc=/var/www/htdocs/coc.html
root-cla=/var/www/htdocs/cla.html
-root-homepage=https://github.com/example
-root-homepage-title=GitHub
+root-link=GitHub|https://github.com/example
+root-link=GitLab|https://gitlab.com/example
+root-link=Codeberg|https://codeberg.org/example
# Allow download of tar.gz, tar.bz2 and zip-files
diff --git a/tests/setup.sh b/tests/setup.sh
index 54ac2bf5cc..33f0e3cbe8 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -120,8 +120,9 @@ clone-url=git://example.org/\$CGIT_REPO_URL.git
enable-filter-overrides=1
root-coc=$PWD/site-coc.txt
root-cla=$PWD/site-cla.txt
-root-homepage=https://github.com/example
-root-homepage-title=GitHub
+root-link=GitHub|https://github.com/example
+root-link=GitLab|https://gitlab.com/example
+root-link=Codeberg|https://codeberg.org/example
repo.url=foo
repo.path=$PWD/repos/foo/.git
diff --git a/tests/t0114-root-homepage.sh b/tests/t0114-root-homepage.sh
index 932d443b4f..22f1bd463a 100644
--- a/tests/t0114-root-homepage.sh
+++ b/tests/t0114-root-homepage.sh
@@ -1,18 +1,26 @@
#!/bin/sh
-test_description='Check root homepage link'
+test_description='Check root external links'
. ./setup.sh
-test_expect_success 'index has configured root homepage link' '
+test_expect_success 'index has configured root links' '
cgit_url "" >tmp &&
grep "https://github.com/example" tmp &&
- grep ">GitHub<" tmp
+ grep ">GitHub<" tmp &&
+ grep "https://gitlab.com/example" tmp &&
+ grep ">GitLab<" tmp &&
+ grep "https://codeberg.org/example" tmp &&
+ grep ">Codeberg<" tmp
'
-test_expect_success 'root pages keep root homepage link' '
+test_expect_success 'root pages keep root links' '
cgit_query "p=coc" >tmp &&
grep "https://github.com/example" tmp &&
- grep ">GitHub<" tmp
+ grep ">GitHub<" tmp &&
+ grep "https://gitlab.com/example" tmp &&
+ grep ">GitLab<" tmp &&
+ grep "https://codeberg.org/example" tmp &&
+ grep ">Codeberg<" tmp
'
test_done
diff --git a/ui-shared.c b/ui-shared.c
index 2d857c56d8..f8ba28e3cf 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -985,6 +985,17 @@ static const char *hc(const char *page)
return strcmp(ctx.qry.page, page) ? NULL : "active";
}
+static void print_root_link(const char *title, const char *url)
+{
+ if (!url || !url[0])
+ return;
+ html("<a href='");
+ html_attr(url);
+ html("'>");
+ html_txt(title && title[0] ? title : "homepage");
+ html("</a>");
+}
+
static void cgit_print_path_crumbs(char *path)
{
char *old_path = ctx.qry.path;
@@ -1134,6 +1145,7 @@ void cgit_print_pageheader(void)
html("<input type='submit' value='search'/>\n");
html("</form>\n");
} else if (ctx.env.authenticated) {
+ struct string_list_item *item;
char *currenturl = cgit_currenturl();
site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1);
if (ctx.cfg.root_readme)
@@ -1145,14 +1157,11 @@ void cgit_print_pageheader(void)
if (ctx.cfg.root_cla)
site_link("cla", "Contributor License Agreement", NULL,
hc("cla"), NULL, NULL, 0, 1);
- if (ctx.cfg.root_homepage) {
- html("<a href='");
- html_attr(ctx.cfg.root_homepage);
- html("'>");
- html_txt(ctx.cfg.root_homepage_title ?
- ctx.cfg.root_homepage_title : "homepage");
- html("</a>");
- }
+ if (ctx.cfg.root_links.nr)
+ for_each_string_list_item(item, &ctx.cfg.root_links)
+ print_root_link(item->string, item->util);
+ else if (ctx.cfg.root_homepage)
+ print_root_link(ctx.cfg.root_homepage_title, ctx.cfg.root_homepage);
html("</td><td class='form'>");
html("<form method='get' action='");
html_attr(currenturl);