From 24eb4b5a9a411e7d8a7afd518d8f9038d3328fef Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Thu, 29 Oct 2026 13:31:07 -1000 Subject: Name the page first in every title Summary, about, log, refs, tag and stats pages shared one title, so tabs, history and search results could not tell them apart. Titles now read page, repository and site, with root-title as the site, and the description stays in the meta description, where search engines read it. --- MANUAL.txt | 4 ++-- source/cgit.c | 2 +- source/cmd.c | 11 +++++++++-- source/ui-blame.c | 1 + source/ui-shared.c | 10 ++++++++++ source/ui-shared.h | 1 + source/ui-tag.c | 1 + source/ui-tree.c | 1 + tests/t0005-markup.sh | 15 +++++++++++++++ tests/t0113-tag.sh | 5 +++++ 10 files changed, 46 insertions(+), 5 deletions(-) diff --git a/MANUAL.txt b/MANUAL.txt index 48d5561..e14b0dc 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -453,8 +453,8 @@ root-readme:: Default value: none. root-title:: - Text printed as heading on the repository index page. Default value: - "Git repository browser". + Text printed as heading on the repository index page, and last in + the title of every page. Default value: "Git repository browser". scan-hidden-path:: If set to "1" and scan-path is enabled, scan-path recurses into diff --git a/source/cgit.c b/source/cgit.c index a877e92..efcb703 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -1136,7 +1136,7 @@ static int prepare_repo_cmd(int nongit, int err, int clone) ); return 1; } - ctx.page.title = cgit_fmtalloc("%s - %s", ctx.repo->name, ctx.repo->desc); + ctx.page.title = cgit_fmtalloc("%s - %s", ctx.repo->name, ctx.cfg.root_title); if (!ctx.repo->defbranch) ctx.repo->defbranch = guess_defbranch(); diff --git a/source/cmd.c b/source/cmd.c index 8f89e3b..22a6c19 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -43,10 +43,12 @@ static void about_fn(void) return; } if (!ctx.repo) { + cgit_prefix_title("about"); cgit_print_site_readme(); return; } if (ctx.repo->readme.nr) { + cgit_prefix_title("about"); cgit_print_repo_readme(); return; } @@ -83,6 +85,7 @@ static void commit_fn(void) static void diff_fn(void) { + cgit_prefix_title("diff"); cgit_print_diff(ctx.qry.oid, ctx.qry.oid2, ctx.qry.path, 1, 0); } @@ -93,6 +96,7 @@ static void info_fn(void) static void log_fn(void) { + cgit_prefix_title("log"); cgit_print_log( ctx.qry.oid, ctx.qry.ofs, ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search, ctx.qry.path, 1, ctx.repo->enable_commit_graph, @@ -140,6 +144,7 @@ static void rawdiff_fn(void) static void refs_fn(void) { + cgit_prefix_title("refs"); cgit_print_refs(); } @@ -155,10 +160,12 @@ static void snapshot_fn(void) static void stats_fn(void) { - if (ctx.repo->max_stats) + if (ctx.repo->max_stats) { + cgit_prefix_title("stats"); cgit_show_stats(); - else + } else { cgit_print_error_page(404, "Not Found", "Stats are disabled"); + } } static void summary_fn(void) diff --git a/source/ui-blame.c b/source/ui-blame.c index f60020c..48cbf8e 100644 --- a/source/ui-blame.c +++ b/source/ui-blame.c @@ -298,6 +298,7 @@ static void print_blame_page(const struct object_id *oid, const char *path, run_blame(&sb, &revs, path, rev); cgit_set_title_from_path(path); + cgit_prefix_title("blame"); cgit_print_layout_start(); htmlf("
blob: %s (", oid_to_hex(oid)); diff --git a/source/ui-shared.c b/source/ui-shared.c index e7b7d88..8da9878 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -1991,3 +1991,13 @@ void cgit_set_title_from_path(const char *path) strbuf_addf(&sb, " - %s", ctx.page.title); ctx.page.title = strbuf_detach(&sb, NULL); } + +/* + * Names the page ahead of the repository and the site, so that the pages of one + * repository can be told apart in tabs, history and search results. + */ +void cgit_prefix_title(const char *name) +{ + ctx.page.title = cgit_fmtalloc("%s - %s", name, + ctx.page.title ? ctx.page.title : ctx.cfg.root_title); +} diff --git a/source/ui-shared.h b/source/ui-shared.h index 5a1e5fc..da1b889 100644 --- a/source/ui-shared.h +++ b/source/ui-shared.h @@ -141,4 +141,5 @@ extern void cgit_add_hidden_formfields(int incl_head, int incl_search, const cha * Put path in front of the page title, its last component first. */ extern void cgit_set_title_from_path(const char *path); +extern void cgit_prefix_title(const char *name); #endif // CGIT_UI_SHARED_H diff --git a/source/ui-tag.c b/source/ui-tag.c index 5fa8a17..f9ce6b3 100644 --- a/source/ui-tag.c +++ b/source/ui-tag.c @@ -165,6 +165,7 @@ void cgit_print_tag(char *revname) oid_to_hex(&oid)); goto cleanup; } + cgit_prefix_title(revname); if (obj->type == OBJ_TAG) print_annotated_tag(revname, &oid); else diff --git a/source/ui-tree.c b/source/ui-tree.c index 69c0763..95ff337 100644 --- a/source/ui-tree.c +++ b/source/ui-tree.c @@ -526,6 +526,7 @@ void cgit_print_tree(const char *rev, char *path) walk.rev = xstrdup(rev); if (!path) { + cgit_prefix_title("tree"); ls_tree(get_commit_tree_oid(commit), &walk); goto cleanup; } diff --git a/tests/t0005-markup.sh b/tests/t0005-markup.sh index 22ac81c..52d9e34 100755 --- a/tests/t0005-markup.sh +++ b/tests/t0005-markup.sh @@ -90,6 +90,21 @@ test_expect_success 'the blob, blame and about pages open with their own contain grep "
" tmp ' +test_expect_success 'each page names itself, then the repository and the site' ' + site="Git repository browser" && + hooks "hooks/" >tmp && + grep "hooks - $site" tmp && + for page in about log refs tree stats + do + hooks "hooks/$page/" >tmp && + grep "$page - hooks - $site" tmp || return 1 + done && + hooks "hooks/tree/dir/hello.c" >tmp && + grep "hello.c < dir - hooks - $site" tmp && + hooks "hooks/blame/dir/hello.c" >tmp && + grep "blame - hello.c < dir - hooks - $site" tmp +' + # A browser gives these elements a monospace font of its own, which would # otherwise win over the one a theme sets through --font-mono. test_expect_success 'every monospace element takes the theme font' ' diff --git a/tests/t0113-tag.sh b/tests/t0113-tag.sh index b91c7e6..2043385 100755 --- a/tests/t0113-tag.sh +++ b/tests/t0113-tag.sh @@ -86,4 +86,9 @@ test_expect_success 'a signed tag shows its signature in the message' ' ! grep "tmp && + grep "v1.0 - foo - Git repository browser" tmp +' + test_done -- cgit