diff options
| author | Jason A. Dönerfield <no-replay@sl0p.foo> | 2026-07-11 22:02:20 +0200 |
|---|---|---|
| committer | Jason A. Dönerfield <no-replay@sl0p.foo> | 2026-07-11 22:19:08 +0200 |
| commit | f64bb3a19c276303f7502633ffa930a14aa883cc (patch) | |
| tree | 0734b6b680b0361b1dea916f7cddb2ff5de74b2f /ui-summary.c | |
| parent | Bump version (diff) | |
| download | cgit-f64bb3a19c276303f7502633ffa930a14aa883cc.tar.gz cgit-f64bb3a19c276303f7502633ffa930a14aa883cc.tar.xz cgit-f64bb3a19c276303f7502633ffa930a14aa883cc.zip | |
ui-summary: optionally render the repo readme on the summary page
Add enable-summary-readme (global + per-repo repo.enable-summary-readme,
default off). When enabled, the configured readme is rendered inline below the
repository info on the summary page, in addition to the standard about page.
Refactor the readme-rendering core out of cgit_print_repo_readme() into a
static print_readme() helper (no layout wrapper) so the about page and the
summary page share it.
Diffstat (limited to 'ui-summary.c')
| -rw-r--r-- | ui-summary.c | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/ui-summary.c b/ui-summary.c index 947812a..be3c3d9 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -17,6 +17,8 @@ static int urls; +static void print_readme(const char *path); + static void print_url(const char *url) { int columns = 3; @@ -62,6 +64,8 @@ void cgit_print_summary(void) urls = 0; cgit_add_clone_urls(print_url); html("</table>"); + if (ctx.repo->enable_summary_readme) + print_readme(NULL); cgit_print_layout_end(); } @@ -99,24 +103,16 @@ static char* append_readme_path(const char *filename, const char *ref, const cha return full_path; } -void cgit_print_repo_readme(const char *path) +/* Render the configured readme (filtered through the about-filter). The caller + * is responsible for opening/closing the page layout, so this can be reused by + * both the about page and the repo summary page. */ +static void print_readme(const char *path) { - char *filename, *ref, *mimetype; + char *filename, *ref; int free_filename = 0; - mimetype = get_mimetype_for_filename(path); - if (mimetype && (!strncmp(mimetype, "image/", 6) || !strncmp(mimetype, "video/", 6))) { - ctx.page.mimetype = mimetype; - ctx.page.charset = NULL; - cgit_print_plain(); - free(mimetype); - return; - } - free(mimetype); - - cgit_print_layout_start(); if (ctx.repo->readme.nr == 0) - goto done; + return; filename = ctx.repo->readme.items[0].string; ref = ctx.repo->readme.items[0].util; @@ -125,7 +121,7 @@ void cgit_print_repo_readme(const char *path) free_filename = 1; filename = append_readme_path(filename, ref, path); if (!filename) - goto done; + return; } /* Print the calculated readme, either from the git repo or from the @@ -142,7 +138,23 @@ void cgit_print_repo_readme(const char *path) html("</div>"); if (free_filename) free(filename); +} -done: +void cgit_print_repo_readme(const char *path) +{ + char *mimetype; + + mimetype = get_mimetype_for_filename(path); + if (mimetype && (!strncmp(mimetype, "image/", 6) || !strncmp(mimetype, "video/", 6))) { + ctx.page.mimetype = mimetype; + ctx.page.charset = NULL; + cgit_print_plain(); + free(mimetype); + return; + } + free(mimetype); + + cgit_print_layout_start(); + print_readme(path); cgit_print_layout_end(); } |
