-rw-r--r-- | cgit.c | 13 | ||||
-rw-r--r-- | cgit.h | 3 | ||||
-rw-r--r-- | cgitrc.5.txt | 21 | ||||
-rw-r--r-- | ui-atom.c | 2 | ||||
-rw-r--r-- | ui-commit.c | 12 | ||||
-rw-r--r-- | ui-patch.c | 6 | ||||
-rw-r--r-- | ui-plain.c | 20 | ||||
-rw-r--r-- | ui-tag.c | 2 | ||||
-rw-r--r-- | ui-tree.c | 8 |
9 files changed, 74 insertions, 13 deletions
@@ -19,2 +19,10 @@ const char *cgit_version = CGIT_VERSION; +void add_mimetype(const char *name, const char *value) +{ + struct string_list_item *item; + + item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes); + item->util = xstrdup(value); +} + struct cgit_filter *new_filter(const char *cmd, int extra_args) @@ -68,2 +76,4 @@ void config_cb(const char *name, const char *value) ctx.cfg.nocache = atoi(value); + else if (!strcmp(name, "noplainemail")) + ctx.cfg.noplainemail = atoi(value); else if (!strcmp(name, "noheader")) @@ -124,2 +134,4 @@ void config_cb(const char *name, const char *value) ctx.cfg.local_time = atoi(value); + else if (!prefixcmp(name, "mimetype.")) + add_mimetype(name + 9, value); else if (!strcmp(name, "repo.group")) @@ -242,2 +254,3 @@ static void prepare_context(struct cgit_context *ctx) ctx->page.etag = NULL; + memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); } @@ -17,2 +17,3 @@ #include <archive.h> +#include <string-list.h> #include <xdiff-interface.h> @@ -182,2 +183,3 @@ struct cgit_config { int nocache; + int noplainemail; int noheader; @@ -188,2 +190,3 @@ struct cgit_config { int summary_tags; + struct string_list mimetypes; struct cgit_filter *about_filter; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index d8e4b97..4d656fe 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -162,2 +162,6 @@ max-stats:: +mimetype.<ext>:: + Set the mimetype for the specified filename extension. This is used + by the `plain` command when returning blob content. + module-link:: @@ -173,2 +177,6 @@ nocache:: +noplainemail:: + If set to "1" showing full author email adresses will be disabled. + Default value: "0". + noheader:: @@ -357,2 +365,15 @@ snapshots=tar.gz tar.bz2 zip ## +## List of common mimetypes +## + +mimetype.git=image/git +mimetype.html=text/html +mimetype.jpg=image/jpeg +mimetype.jpeg=image/jpeg +mimetype.pdf=application/pdf +mimetype.png=image/png +mimetype.svg=image/svg+xml + + +## ## List of repositories. @@ -34,3 +34,3 @@ void add_entry(struct commit *commit, char *host) } - if (info->author_email) { + if (info->author_email && !ctx.cfg.noplainemail) { mail = xstrdup(info->author_email); diff --git a/ui-commit.c b/ui-commit.c index 5815b58..d6b73ee 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -42,4 +42,6 @@ void cgit_print_commit(char *hex) html_txt(info->author); - html(" "); - html_txt(info->author_email); + if (!ctx.cfg.noplainemail) { + html(" "); + html_txt(info->author_email); + } html("</td><td class='right'>"); @@ -49,4 +51,6 @@ void cgit_print_commit(char *hex) html_txt(info->committer); - html(" "); - html_txt(info->committer_email); + if (!ctx.cfg.noplainemail) { + html(" "); + html_txt(info->committer_email); + } html("</td><td class='right'>"); @@ -110,3 +110,7 @@ void cgit_print_patch(char *hex) htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); - htmlf("From: %s %s\n", info->author, info->author_email); + htmlf("From: %s", info->author); + if (!ctx.cfg.noplainemail) { + htmlf(" %s", info->author_email); + } + html("\n"); html("Date: "); @@ -19,4 +19,5 @@ static void print_object(const unsigned char *sha1, const char *path) enum object_type type; - char *buf; + char *buf, *ext; unsigned long size; + struct string_list_item *mime; @@ -33,6 +34,15 @@ static void print_object(const unsigned char *sha1, const char *path) } - if (buffer_is_binary(buf, size)) - ctx.page.mimetype = "application/octet-stream"; - else - ctx.page.mimetype = "text/plain"; + ctx.page.mimetype = NULL; + ext = strrchr(path, '.'); + if (ext && *(++ext)) { + mime = string_list_lookup(ext, &ctx.cfg.mimetypes); + if (mime) + ctx.page.mimetype = (char *)mime->util; + } + if (!ctx.page.mimetype) { + if (buffer_is_binary(buf, size)) + ctx.page.mimetype = "application/octet-stream"; + else + ctx.page.mimetype = "text/plain"; + } ctx.page.filename = fmt("%s", path); @@ -66,3 +66,3 @@ void cgit_print_tag(char *revname) html_txt(info->tagger); - if (info->tagger_email) { + if (info->tagger_email && !ctx.cfg.noplainemail) { html(" "); @@ -115,2 +115,3 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen, char *fullpath; + char *class; enum object_type type; @@ -147,3 +148,8 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen, } else { - cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, + class = strrchr(name, '.'); + if (class != NULL) { + class = fmt("ls-blob %s", class + 1); + } else + class = "ls-blob"; + cgit_tree_link(name, NULL, class, ctx.qry.head, curr_rev, fullpath); |