From f64bb3a19c276303f7502633ffa930a14aa883cc Mon Sep 17 00:00:00 2001 From: "Jason A. Dönerfield" Date: Sat, 11 Jul 2026 22:02:20 +0200 Subject: 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. --- ui-summary.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'ui-summary.c') 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(""); + 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(""); 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(); } -- cgit v1.3.1-sl0p