Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Small feature for cgit: better breadcrumbs

I wrote a small patch that improves the breadcrumbs navigation in cgit. The admin of the mailing list (where discussions and patches go, supposedly) never replied to me and I never got any notifications about it. But I was going to share it here anyway.

Check out the patch in my cgit, or included below here.

files/2026/listings/ui-shared-add-section-breadcrumbs-links.patch (Source)

From 1f3d3876bdaab0bd27a564d292172aa72e14d906 Mon Sep 17 00:00:00 2001
From: "B. Stack" <bgstack15@gmail.com>
Date: Sun, 30 Aug 2026 19:05:43 -0400
Subject: ui-shared: add section breadcrumb links
When section-from-path is enabled, include a link to the section, if any,
in the header breadcrumbs.
This patch was developed with assistance from an AI coding tool (duck.ai).
I reviewed and tested the resulting code and take responsibility for the
patch.
Signed-off-by: B. Stack <bgstack15@gmail.com>
---
ui-shared.c | 17 +++++++++++++++++
ui-shared.h |  1 +
2 files changed, 18 insertions(+)
diff --git a/ui-shared.c b/ui-shared.c
index df52a9b..43b0e06 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -330,6 +330,19 @@ static void reporevlink(const char *page, const char *name, const char *title,
html("</a>");
}
+void cgit_section_link(const char *name, const char *section)
+{
+ const char *root = cgit_rooturl();
+ html("<a href='");
+ html_attr(root);
+ if (root[0] && root[strlen(root) - 1] != '/')
+ html("/");
+ html_attr(section);
+ html("/'>");
+ html_txt(name);
+ html("</a>");
+}
+
void cgit_summary_link(const char *name, const char *title, const char *class,
       const char *head)
{
@@ -1040,6 +1053,10 @@ static void print_header(void)
html("<td class='main'>");
if (ctx.repo) {
cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);
+ if (ctx.repo->section && *ctx.repo->section) {
+ html(" : ");
+ cgit_section_link(ctx.repo->section, ctx.repo->section);
+ }
html(" : ");
cgit_summary_link(ctx.repo->name, NULL, NULL, NULL);
if (ctx.env.authenticated) {
diff --git a/ui-shared.h b/ui-shared.h
index 2a3a7f5..d521a97 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -17,6 +17,7 @@ extern void cgit_add_clone_urls(void (*fn)(const char *));
extern void cgit_index_link(const char *name, const char *title,
    const char *class, const char *pattern, const char *sort, int ofs, int always_root);
+extern void cgit_section_link(const char *name, const char *section);
extern void cgit_summary_link(const char *name, const char *title,
      const char *class, const char *head);
extern void cgit_tag_link(const char *name, const char *title,
--
cgit

I spend a lot of time in a grouping, and wanted a quick link back to it.

Comments