From mboxrd@z Thu Jan 1 00:00:00 1970 From: list at eworm.de (Christian Hesse) Date: Fri, 14 Aug 2015 23:16:36 +0200 Subject: [PATCH 2/3] about: send images plain In-Reply-To: <20150814151335.GB1412@serenity.lan> References: <20150814151335.GB1412@serenity.lan> Message-ID: <1439586997-25333-1-git-send-email-list@eworm.de> From: Christian Hesse 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 --- ui-summary.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/ui-summary.c b/ui-summary.c index fb04dc3..99c9234 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -9,9 +9,10 @@ #include "cgit.h" #include "ui-summary.h" #include "html.h" +#include "ui-blob.h" #include "ui-log.h" +#include "ui-plain.h" #include "ui-refs.h" -#include "ui-blob.h" #include "ui-shared.h" static int urls; @@ -100,8 +101,38 @@ static char* append_readme_path(const char *filename, const char *ref, const cha void cgit_print_repo_readme(char *path) { - char *filename, *ref; + char *ext = NULL, *filename, *ref, *mimetype = NULL; int free_filename = 0; + int freemime = 0; + struct string_list_item *mime; + + 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(); + + if (freemime) + free(mimetype); + + return; + } + + if (freemime) + free(mimetype); cgit_print_layout_start(); if (ctx.repo->readme.nr == 0) -- 2.5.0