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 | |
| 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.
| -rw-r--r-- | cgit.c | 6 | ||||
| -rw-r--r-- | cgit.h | 2 | ||||
| -rw-r--r-- | cgitrc.5.txt | 9 | ||||
| -rw-r--r-- | shared.c | 1 | ||||
| -rw-r--r-- | ui-summary.c | 44 |
5 files changed, 46 insertions, 16 deletions
@@ -72,6 +72,8 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu repo->enable_log_filecount = atoi(value); else if (!strcmp(name, "enable-log-linecount")) repo->enable_log_linecount = atoi(value); + else if (!strcmp(name, "enable-summary-readme")) + repo->enable_summary_readme = atoi(value); else if (!strcmp(name, "enable-remote-branches")) repo->enable_remote_branches = atoi(value); else if (!strcmp(name, "enable-subject-links")) @@ -191,6 +193,8 @@ static void config_cb(const char *name, const char *value) ctx.cfg.enable_log_filecount = atoi(value); else if (!strcmp(name, "enable-log-linecount")) ctx.cfg.enable_log_linecount = atoi(value); + else if (!strcmp(name, "enable-summary-readme")) + ctx.cfg.enable_summary_readme = atoi(value); else if (!strcmp(name, "enable-remote-branches")) ctx.cfg.enable_remote_branches = atoi(value); else if (!strcmp(name, "enable-subject-links")) @@ -824,6 +828,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) repo->enable_log_filecount); fprintf(f, "repo.enable-log-linecount=%d\n", repo->enable_log_linecount); + fprintf(f, "repo.enable-summary-readme=%d\n", + repo->enable_summary_readme); if (repo->about_filter && repo->about_filter != ctx.cfg.about_filter) cgit_fprintf_filter(repo->about_filter, f, "repo.about-filter="); if (repo->commit_filter && repo->commit_filter != ctx.cfg.commit_filter) @@ -107,6 +107,7 @@ struct cgit_repo { int enable_remote_branches; int enable_subject_links; int enable_html_serving; + int enable_summary_readme; int max_stats; int branch_sort; int commit_sort; @@ -241,6 +242,7 @@ struct cgit_config { int enable_remote_branches; int enable_subject_links; int enable_html_serving; + int enable_summary_readme; int enable_tree_linenumbers; int enable_git_config; int local_time; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 7c39bf9..57839e4 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -197,6 +197,11 @@ enable-log-filecount:: modified files for each commit on the repository log page. Default value: "0". +enable-summary-readme:: + Flag which, when set to "1", will make cgit render the repository's + readme (see 'readme') inline below the info on the repo summary page, + in addition to the standard "about" page. Default value: "0". + enable-log-linecount:: Flag which, when set to "1", will make cgit print the number of added and removed lines for each commit on the repository log page. Default @@ -519,6 +524,10 @@ repo.enable-log-linecount:: A flag which can be used to disable the global setting `enable-log-linecount'. Default value: none. +repo.enable-summary-readme:: + A flag which can be used to override the global setting + `enable-summary-readme'. Default value: none. + repo.enable-remote-branches:: Flag which, when set to "1", will make cgit display remote branches in the summary and refs views. Default value: <enable-remote-branches>. @@ -68,6 +68,7 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->enable_log_linecount = ctx.cfg.enable_log_linecount; ret->enable_remote_branches = ctx.cfg.enable_remote_branches; ret->enable_subject_links = ctx.cfg.enable_subject_links; + ret->enable_summary_readme = ctx.cfg.enable_summary_readme; ret->enable_html_serving = ctx.cfg.enable_html_serving; ret->max_stats = ctx.cfg.max_stats; ret->branch_sort = ctx.cfg.branch_sort; 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(); } |
