Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Lead an error page's title with the error
The config error page had a title of its own, in the reverse order,
and now takes the same one as any other 404, since its message
already says the repository failed to open.
| -rw-r--r-- | source/cgit.c | 3 | |
| -rw-r--r-- | source/ui-shared.c | 10 | |
| -rwxr-xr-x | tests/t0005-markup.sh | 13 |
3 files changed, 21 insertions, 5 deletions
diff --git a/source/cgit.c b/source/cgit.c index 39e8ab8..dc483ee 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -1182,8 +1182,6 @@ static int prepare_repo_cmd(int nongit, int err, int clone) strbuf_reset(&title); if (nongit) { const char *name = ctx.repo->name; - strbuf_addf(&title, "%s - %s", ctx.cfg.root_title, "config error"); - ctx.page.title = title.buf; ctx.repo = NULL; cgit_print_error_page( 404, "Not Found", "Failed to open %s: %s", name, @@ -1268,7 +1266,6 @@ static void process_request(void) // branch switcher needs the head resolved first. if (ctx.repo && prepare_repo_cmd(nongit, err, 0)) return; - ctx.page.title = "cgit error"; cgit_print_error_page(404, "Not Found", "Invalid request"); return; } diff --git a/source/ui-shared.c b/source/ui-shared.c index 0865ffa..e346cbd 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -1457,8 +1457,8 @@ static void print_docstart(void) html("<meta name='theme-color' media='(prefers-color-scheme: light)' content='#ffffff'>\n"); html("<meta name='theme-color' media='(prefers-color-scheme: dark)' content='#1b1b1b'>\n"); html("<title>"); - // An error page reached before a title was chosen still has to name - // itself, since an empty title element is not valid. + // 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); // The auth page goes out before the repository is opened, when // pinned_oid cannot resolve anything yet. @@ -1542,6 +1542,12 @@ void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) } ctx.page.status = code; ctx.page.statusmsg = msg; + // The error stands where a page would name itself, ahead of the + // repository and the site. + if (ctx.repo) + ctx.page.title = xstrfmt("%s - %s - %s", msg, ctx.repo->name, ctx.cfg.root_title); + else + ctx.page.title = xstrfmt("%s - %s", msg, ctx.cfg.root_title); // A page that had already chosen another type, such as an image // served through the about page, still answers its error as html. ctx.page.mimetype = "text/html"; diff --git a/tests/t0005-markup.sh b/tests/t0005-markup.sh index a6dd028..3260e49 100755 --- a/tests/t0005-markup.sh +++ b/tests/t0005-markup.sh @@ -118,6 +118,19 @@ test_expect_success 'each page names itself, then the repository and the site' ' grep "<title>blame - hello.c < dir - hooks - $site</title>" tmp ' +test_expect_success 'an error page names the error where a page names itself' ' + site="Git repository browser" && + cgit_rc hooksrc "url=hooks/tree/missing" >tmp && + grep "^Status: 404" tmp && + grep "<title>Not Found - hooks - $site</title>" tmp && + cgit_rc hooksrc "url=hooks/nonsense/" >tmp && + grep "<title>Not Found - hooks - $site</title>" tmp && + cgitrc_repo brokenrc broken "repo.path=$PWD/nowhere" && + cgit_rc brokenrc "url=broken/" >tmp && + grep "Failed to open broken" tmp && + grep "<title>Not Found - $site</title>" 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' ' |
