Diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/ui-shared.c | 31 |
1 file changed, 28 insertions, 3 deletions
diff --git a/source/ui-shared.c b/source/ui-shared.c index cb5e050..788551d 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -1442,10 +1442,31 @@ void cgit_redirect(const char *url, const char *query, bool permanent) html("\n\n"); } +/* + * A repository page's title runs page - repository - site, apart from the + * summary's, which has no page name and opens with the repository. Answer the + * length of the name the title opens with. + */ +static size_t title_name_len(const char *title) +{ + struct strbuf tail = STRBUF_INIT; + size_t len = strlen(title); + + strbuf_addf(&tail, " - %s", ctx.cfg.root_title); + if (strip_suffix_mem(title, &len, tail.buf)) { + strbuf_reset(&tail); + strbuf_addf(&tail, " - %s", ctx.repo->name); + strip_suffix_mem(title, &len, tail.buf); + } + strbuf_release(&tail); + return len; +} + static void print_docstart(void) { const struct object_id *pinned; struct string_list_item *item; + struct strbuf title = STRBUF_INIT; const char *desc, *robots; char *host; @@ -1466,11 +1487,15 @@ static void print_docstart(void) html("<title>"); // A page that chose no title still has to name itself, since an empty // title element is not valid. - html_txt(ctx.page.title ? ctx.page.title : ctx.cfg.root_title); + strbuf_addstr(&title, ctx.page.title ? ctx.page.title : ctx.cfg.root_title); // The auth page goes out before the repository is opened, when - // pinned_oid cannot resolve anything yet. + // pinned_oid cannot resolve anything yet. The commit is the page's, so + // it is named with the page, ahead of the repository and the site. if (ctx.env.authenticated && (pinned = pinned_oid())) - html_txtf(" @ %.*s", SHORT_HASH_LEN, oid_to_hex(pinned)); + strbuf_insertf(&title, title_name_len(title.buf), " @ %.*s", + SHORT_HASH_LEN, oid_to_hex(pinned)); + html_txt(title.buf); + strbuf_release(&title); html("</title>\n"); // The placeholder a scanned repository carries instead of a description // is left out, since it describes nothing. Until the auth filter lets |
