From: Christian Hesse <[email protected]>

The about page used to display just fine, but images were broken: The
binary image data was embedded in html code.
Use cgit_print_plain() to send images in plain mode and make them
available on about page.

Signed-off-by: Christian Hesse <[email protected]>
---
 cmd.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/cmd.c b/cmd.c
index 20c80b0..d77ee63 100644
--- a/cmd.c
+++ b/cmd.c
@@ -43,8 +43,37 @@ static void about_fn(void)
                    ctx.qry.url[strlen(ctx.qry.url) - 1] != '/' &&
                    ctx.env.path_info[strlen(ctx.env.path_info) - 1] != '/')
                        cgit_redirect(fmtalloc("%s/", cgit_currenturl()), true);
-               else
-                       cgit_print_repo_readme(ctx.qry.path);
+               else {
+                       char *ext = NULL;
+                       int freemime = 0;
+                       struct string_list_item *mime;
+                       char * mimetype = NULL;
+
+                       if (ctx.qry.path)
+                               ext = strrchr(ctx.qry.path, '.');
+
+                       if (ext && *(++ext)) {
+                               mime = string_list_lookup(&ctx.cfg.mimetypes, 
ext);
+                               if (mime) {
+                                       mimetype = (char *)mime->util;
+                               } else {
+                                       mimetype = 
get_mimetype_from_file(ctx.cfg.mimetype_file, ext);
+                                       if (mimetype)
+                                               freemime = 1;
+                               }
+                       }
+
+                       if (mimetype && strncmp(mimetype, "image/", 6) == 0) {
+                               ctx.page.mimetype = mimetype;
+                               ctx.page.charset = NULL;
+                               cgit_print_plain();
+                       } else
+                               cgit_print_repo_readme(ctx.qry.path);
+
+                       /* If we allocated this, then casting away const is 
safe. */
+                       if (freemime)
+                               free(mimetype);
+               }
        } else
                cgit_print_site_readme();
 }
-- 
2.5.0

_______________________________________________
CGit mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/cgit

Reply via email to