* Images on about page @ 2014-04-17 10:13 list 2014-04-17 10:18 ` list 0 siblings, 1 reply; 14+ messages in thread From: list @ 2014-04-17 10:13 UTC (permalink / raw) Hello everybody, I have some README files in markdown that include images. The page itself is generated as expected, but the images fail: cgit returns a html page with binary data included. Any chance to just return the binary data with proper http header ("Content-Type: image/png" in this case)? -- main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH" "CX:;",b;for(a/* Chris get my mail address: */=0;b=c[a++];) putchar(b-1/(/* gcc -o sig sig.c && ./sig */b/42*2-3)*42);} -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20140417/32b3611f/attachment.asc> ^ permalink raw reply [flat|nested] 14+ messages in thread
* Images on about page 2014-04-17 10:13 Images on about page list @ 2014-04-17 10:18 ` list 2014-04-17 10:19 ` [PATCH 1/1] filters: in markdown get images from their plain url mail 0 siblings, 1 reply; 14+ messages in thread From: list @ 2014-04-17 10:18 UTC (permalink / raw) Christian Hesse <list at eworm.de> on Thu, 2014/04/17 12:13: > Hello everybody, > > I have some README files in markdown that include images. The page itself is > generated as expected, but the images fail: cgit returns a html page with > binary data included. Any chance to just return the binary data with proper > http header ("Content-Type: image/png" in this case)? Ah, found a simple solution myself... Will reply with a patch. -- main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH" "CX:;",b;for(a/* Chris get my mail address: */=0;b=c[a++];) putchar(b-1/(/* gcc -o sig sig.c && ./sig */b/42*2-3)*42);} -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20140417/725d01da/attachment.asc> ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] filters: in markdown get images from their plain url 2014-04-17 10:18 ` list @ 2014-04-17 10:19 ` mail 2014-04-17 10:57 ` Jason 0 siblings, 1 reply; 14+ messages in thread From: mail @ 2014-04-17 10:19 UTC (permalink / raw) --- filters/html-converters/resources/markdown.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filters/html-converters/resources/markdown.pl b/filters/html-converters/resources/markdown.pl index 34337c2..01c719d 100755 --- a/filters/html-converters/resources/markdown.pl +++ b/filters/html-converters/resources/markdown.pl @@ -925,7 +925,7 @@ sub _DoImages { my $url = $g_urls{$link_id}; $url =~ s! \* !$g_escape_table{'*'}!gx; # We've got to encode these to avoid $url =~ s! _ !$g_escape_table{'_'}!gx; # conflicting with italics/bold. - $result = "<img src=\"$url\" alt=\"$alt_text\""; + $result = "<img src=\"../plain/$url\" alt=\"$alt_text\""; if (defined $g_titles{$link_id}) { my $title = $g_titles{$link_id}; $title =~ s! \* !$g_escape_table{'*'}!gx; @@ -977,7 +977,7 @@ sub _DoImages { $title =~ s/"/"/g; $url =~ s! \* !$g_escape_table{'*'}!gx; # We've got to encode these to avoid $url =~ s! _ !$g_escape_table{'_'}!gx; # conflicting with italics/bold. - $result = "<img src=\"$url\" alt=\"$alt_text\""; + $result = "<img src=\"../plain/$url\" alt=\"$alt_text\""; if (defined $title) { $title =~ s! \* !$g_escape_table{'*'}!gx; $title =~ s! _ !$g_escape_table{'_'}!gx; -- 1.9.2 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] filters: in markdown get images from their plain url 2014-04-17 10:19 ` [PATCH 1/1] filters: in markdown get images from their plain url mail @ 2014-04-17 10:57 ` Jason 2014-04-17 11:02 ` mail 0 siblings, 1 reply; 14+ messages in thread From: Jason @ 2014-04-17 10:57 UTC (permalink / raw) Clever solution. But this breaks if we're ever including an image by an absolute URL. Maybe we should simply document that git-relative images should be linked via "../plain/" and leave it to the markdown author? Or come up with some other clever hack? ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] filters: in markdown get images from their plain url 2014-04-17 10:57 ` Jason @ 2014-04-17 11:02 ` mail 2014-04-17 11:42 ` mail 0 siblings, 1 reply; 14+ messages in thread From: mail @ 2014-04-17 11:02 UTC (permalink / raw) "Jason A. Donenfeld" <Jason at zx2c4.com> on Thu, 2014/04/17 12:57: > Clever solution. > > But this breaks if we're ever including an image by an absolute URL. You are right... > Maybe we should simply document that git-relative images should be > linked via "../plain/" and leave it to the markdown author? This works for cgit but breaks every other markdown use case. > Or come up with some other clever hack? Will think about it. ;) -- Schoene Gruesse Chris O< ascii ribbon campaign stop html mail - www.asciiribbon.org -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20140417/e2d24feb/attachment.asc> ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] filters: in markdown get images from their plain url 2014-04-17 11:02 ` mail @ 2014-04-17 11:42 ` mail 2014-04-17 11:44 ` Jason 0 siblings, 1 reply; 14+ messages in thread From: mail @ 2014-04-17 11:42 UTC (permalink / raw) URLs starting with two slashes or containing '://' are expected to be absolut and therefore not modified. Relative URLs are prefixed with '../plain/' to get a plain version from cgit. --- filters/html-converters/resources/markdown.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/filters/html-converters/resources/markdown.pl b/filters/html-converters/resources/markdown.pl index 34337c2..365f8b6 100755 --- a/filters/html-converters/resources/markdown.pl +++ b/filters/html-converters/resources/markdown.pl @@ -925,6 +925,7 @@ sub _DoImages { my $url = $g_urls{$link_id}; $url =~ s! \* !$g_escape_table{'*'}!gx; # We've got to encode these to avoid $url =~ s! _ !$g_escape_table{'_'}!gx; # conflicting with italics/bold. + $url = "../plain/$url" unless $url =~ m/(^|:)\/\//; $result = "<img src=\"$url\" alt=\"$alt_text\""; if (defined $g_titles{$link_id}) { my $title = $g_titles{$link_id}; @@ -977,6 +978,7 @@ sub _DoImages { $title =~ s/"/"/g; $url =~ s! \* !$g_escape_table{'*'}!gx; # We've got to encode these to avoid $url =~ s! _ !$g_escape_table{'_'}!gx; # conflicting with italics/bold. + $url = "../plain/$url" unless $url =~ m/(^|:)\/\//; $result = "<img src=\"$url\" alt=\"$alt_text\""; if (defined $title) { $title =~ s! \* !$g_escape_table{'*'}!gx; -- 1.9.2 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] filters: in markdown get images from their plain url 2014-04-17 11:42 ` mail @ 2014-04-17 11:44 ` Jason 2014-04-17 12:14 ` list 0 siblings, 1 reply; 14+ messages in thread From: Jason @ 2014-04-17 11:44 UTC (permalink / raw) Hmm still not perfect though. Let's say I want a relative URL that is out of the cgit root but still on the same domain... ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] filters: in markdown get images from their plain url 2014-04-17 11:44 ` Jason @ 2014-04-17 12:14 ` list 2014-04-17 13:19 ` [PATCH 1/1] about: return images in plain mode mail 0 siblings, 1 reply; 14+ messages in thread From: list @ 2014-04-17 12:14 UTC (permalink / raw) "Jason A. Donenfeld" <Jason at zx2c4.com> on Thu, 2014/04/17 13:44: > Hmm still not perfect though. Let's say I want a relative URL that is > out of the cgit root but still on the same domain... Probably it's better to do it right... The best solution would be to have cgit itself handle it. Looking at the mime type may be an option, just returning binary data in case of an image. Sadly cgit has already printed some html stuff when about_fn() is called... Looks like this would require some bigger changes. -- main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH" "CX:;",b;for(a/* Chris get my mail address: */=0;b=c[a++];) putchar(b-1/(/* gcc -o sig sig.c && ./sig */b/42*2-3)*42);} -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20140417/52f71243/attachment-0001.asc> ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] about: return images in plain mode 2014-04-17 12:14 ` list @ 2014-04-17 13:19 ` mail 2014-04-17 13:21 ` list 0 siblings, 1 reply; 14+ messages in thread From: mail @ 2014-04-17 13:19 UTC (permalink / raw) --- cgit.h | 2 ++ cmd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- shared.c | 41 +++++++++++++++++++++++++++++++++++++++++ ui-plain.c | 40 ---------------------------------------- 4 files changed, 91 insertions(+), 44 deletions(-) diff --git a/cgit.h b/cgit.h index 0badc64..f2a1d3b 100644 --- a/cgit.h +++ b/cgit.h @@ -373,4 +373,6 @@ extern int readfile(const char *path, char **buf, size_t *size); extern char *expand_macros(const char *txt); +extern char *get_mimetype_from_file(const char *filename, const char *ext); + #endif /* CGIT_H */ diff --git a/cmd.c b/cmd.c index 188cd56..76d892e 100644 --- a/cmd.c +++ b/cmd.c @@ -38,10 +38,54 @@ static void atom_fn(void) static void about_fn(void) { - if (ctx.repo) - cgit_print_repo_readme(ctx.qry.path); - else + if (ctx.repo) { + 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_http_headers(); + cgit_print_docstart(); + cgit_print_pageheader(); + + cgit_print_repo_readme(ctx.qry.path); + + cgit_print_docend(); + } + + /* If we allocated this, then casting away const is safe. */ + if (freemime) + free(mimetype); + + } else { + cgit_print_http_headers(); + cgit_print_docstart(); + cgit_print_pageheader(); + cgit_print_site_readme(); + + cgit_print_docend(); + } + } static void blob_fn(void) @@ -144,7 +188,7 @@ struct cgit_cmd *cgit_get_cmd(void) static struct cgit_cmd cmds[] = { def_cmd(HEAD, 1, 0, 0, 1), def_cmd(atom, 1, 0, 0, 0), - def_cmd(about, 0, 1, 0, 0), + def_cmd(about, 0, 0, 0, 0), def_cmd(blob, 1, 0, 0, 0), def_cmd(commit, 1, 1, 1, 0), def_cmd(diff, 1, 1, 1, 0), diff --git a/shared.c b/shared.c index 8ed14c0..651b771 100644 --- a/shared.c +++ b/shared.c @@ -557,3 +557,44 @@ char *expand_macros(const char *txt) } return result; } + +char *get_mimetype_from_file(const char *filename, const char *ext) +{ + static const char *delimiters; + char *result; + FILE *fd; + char line[1024]; + char *mimetype; + char *token; + + if (!filename) + return NULL; + + fd = fopen(filename, "r"); + if (!fd) + return NULL; + + delimiters = " \t\r\n"; + result = NULL; + + /* loop over all lines in the file */ + while (!result && fgets(line, sizeof(line), fd)) { + mimetype = strtok(line, delimiters); + + /* skip empty lines and comment lines */ + if (!mimetype || (mimetype[0] == '#')) + continue; + + /* loop over all extensions of mimetype */ + while ((token = strtok(NULL, delimiters))) { + if (!strcasecmp(ext, token)) { + result = xstrdup(mimetype); + break; + } + } + } + fclose(fd); + + return result; +} + diff --git a/ui-plain.c b/ui-plain.c index 30fff89..ef7b274 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -17,46 +17,6 @@ struct walk_tree_context { int match; }; -static char *get_mimetype_from_file(const char *filename, const char *ext) -{ - static const char *delimiters; - char *result; - FILE *fd; - char line[1024]; - char *mimetype; - char *token; - - if (!filename) - return NULL; - - fd = fopen(filename, "r"); - if (!fd) - return NULL; - - delimiters = " \t\r\n"; - result = NULL; - - /* loop over all lines in the file */ - while (!result && fgets(line, sizeof(line), fd)) { - mimetype = strtok(line, delimiters); - - /* skip empty lines and comment lines */ - if (!mimetype || (mimetype[0] == '#')) - continue; - - /* loop over all extensions of mimetype */ - while ((token = strtok(NULL, delimiters))) { - if (!strcasecmp(ext, token)) { - result = xstrdup(mimetype); - break; - } - } - } - fclose(fd); - - return result; -} - static int print_object(const unsigned char *sha1, const char *path) { enum object_type type; -- 1.9.2 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] about: return images in plain mode 2014-04-17 13:19 ` [PATCH 1/1] about: return images in plain mode mail @ 2014-04-17 13:21 ` list 2014-04-30 8:37 ` mail 2014-06-29 20:14 ` list 0 siblings, 2 replies; 14+ messages in thread From: list @ 2014-04-17 13:21 UTC (permalink / raw) Christian Hesse <mail at eworm.de> on Thu, 2014/04/17 15:19: > --- > cgit.h | 2 ++ > cmd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- > shared.c | 41 +++++++++++++++++++++++++++++++++++++++++ > ui-plain.c | 40 ---------------------------------------- > 4 files changed, 91 insertions(+), 44 deletions(-) This is a bit quick and dirty, but it works. Are you fine with something like this if we polish it a bit? BTW, this solution fixes images for static html as well, so definitely the way to go I think. -- main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH" "CX:;",b;for(a/* Chris get my mail address: */=0;b=c[a++];) putchar(b-1/(/* gcc -o sig sig.c && ./sig */b/42*2-3)*42);} -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20140417/bd90b46d/attachment.asc> ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] about: return images in plain mode 2014-04-17 13:21 ` list @ 2014-04-30 8:37 ` mail 2014-06-29 20:14 ` list 1 sibling, 0 replies; 14+ messages in thread From: mail @ 2014-04-30 8:37 UTC (permalink / raw) Christian Hesse <list at eworm.de> on Thu, 2014/04/17 15:21: > Christian Hesse <mail at eworm.de> on Thu, 2014/04/17 15:19: > > --- > > cgit.h | 2 ++ > > cmd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- > > shared.c | 41 +++++++++++++++++++++++++++++++++++++++++ > > ui-plain.c | 40 ---------------------------------------- > > 4 files changed, 91 insertions(+), 44 deletions(-) > > This is a bit quick and dirty, but it works. Are you fine with something > like this if we polish it a bit? > > BTW, this solution fixes images for static html as well, so definitely the > way to go I think. Any comments on this? -- Schoene Gruesse Chris O< ascii ribbon campaign stop html mail - www.asciiribbon.org -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20140430/5a61996c/attachment.asc> ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] about: return images in plain mode 2014-04-17 13:21 ` list 2014-04-30 8:37 ` mail @ 2014-06-29 20:14 ` list 2014-06-29 21:07 ` Jason 1 sibling, 1 reply; 14+ messages in thread From: list @ 2014-06-29 20:14 UTC (permalink / raw) Christian Hesse <list at eworm.de> on Thu, 2014/04/17 15:21: > Christian Hesse <mail at eworm.de> on Thu, 2014/04/17 15:19: > > --- > > cgit.h | 2 ++ > > cmd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- > > shared.c | 41 +++++++++++++++++++++++++++++++++++++++++ > > ui-plain.c | 40 ---------------------------------------- > > 4 files changed, 91 insertions(+), 44 deletions(-) > > This is a bit quick and dirty, but it works. Are you fine with something > like this if we polish it a bit? > > BTW, this solution fixes images for static html as well, so definitely the > way to go I think. Now that the list becomes more alive... Any news or comments on this topic? This about page should show a QR-Code: http://cgit.eworm.de/cgit.cgi/cqrlogo/about/ Compare to the github site: https://github.com/eworm-de/cqrlogo#cqrlogo -- main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH" "CX:;",b;for(a/* Chris get my mail address: */=0;b=c[a++];) putchar(b-1/(/* gcc -o sig sig.c && ./sig */b/42*2-3)*42);} -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 473 bytes Desc: not available URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20140629/b5ea36f3/attachment.asc> ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] about: return images in plain mode 2014-06-29 20:14 ` list @ 2014-06-29 21:07 ` Jason 2014-06-30 6:31 ` list 0 siblings, 1 reply; 14+ messages in thread From: Jason @ 2014-06-29 21:07 UTC (permalink / raw) It still seems a bit hackish to me. I need to think about it more, or hear some other ideas on it. ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] about: return images in plain mode 2014-06-29 21:07 ` Jason @ 2014-06-30 6:31 ` list 0 siblings, 0 replies; 14+ messages in thread From: list @ 2014-06-30 6:31 UTC (permalink / raw) "Jason A. Donenfeld" <Jason at zx2c4.com> on Sun, 2014/06/29 23:07: > It still seems a bit hackish to me. That is what I said myself. ;) > I need to think about it more, or > hear some other ideas on it. This is more of a proof of concept than code you should merge. If you agree this is a good idea in general we should think about a clean way to implement it. -- main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH" "CX:;",b;for(a/* Chris get my mail address: */=0;b=c[a++];) putchar(b-1/(/* gcc -o sig sig.c && ./sig */b/42*2-3)*42);} -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 473 bytes Desc: not available URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20140630/13401365/attachment.asc> ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2014-06-30 6:31 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-04-17 10:13 Images on about page list 2014-04-17 10:18 ` list 2014-04-17 10:19 ` [PATCH 1/1] filters: in markdown get images from their plain url mail 2014-04-17 10:57 ` Jason 2014-04-17 11:02 ` mail 2014-04-17 11:42 ` mail 2014-04-17 11:44 ` Jason 2014-04-17 12:14 ` list 2014-04-17 13:19 ` [PATCH 1/1] about: return images in plain mode mail 2014-04-17 13:21 ` list 2014-04-30 8:37 ` mail 2014-06-29 20:14 ` list 2014-06-29 21:07 ` Jason 2014-06-30 6:31 ` list
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).