neocgit

a more 'modern' version of cgit
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/neocgit

commit b47a0f4f50a717877214d3448c59e0e5ef8d8ff9
parent caa714c1800a5020ffb15c24365537ff561a1c92
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Wed,  4 Jul 2018 17:43:59 +0200

NEW: Gravatar image generation without script

Signed-off-by: Ne02ptzero <louis@ne02ptzero.me>

Diffstat:
Mcgit.h | 2++
Mcgit.mk | 2++
Mfilter.c | 18++++++++++++++++++
Mui-log.c | 6+-----
Mui-shared.c | 4+---
5 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/cgit.h b/cgit.h @@ -392,4 +392,6 @@ extern char *expand_macros(const char *txt); extern char *get_mimetype_for_filename(const char *filename); +extern void gravatar_img(const char *email, size_t size); + #endif /* CGIT_H */ diff --git a/cgit.mk b/cgit.mk @@ -58,6 +58,8 @@ ifneq (,$(filter $(uname_S),Linux GNU GNU/kFreeBSD)) CGIT_LIBS += -ldl endif +CGIT_LIBS += -lssl -lcrypto + # glibc 2.1+ offers sendfile which the most common C library on Linux ifeq ($(uname_S),Linux) HAVE_LINUX_SENDFILE = YesPlease diff --git a/filter.c b/filter.c @@ -14,6 +14,7 @@ #include <lualib.h> #include <lauxlib.h> #endif +#include <openssl/md5.h> static inline void reap_filter(struct cgit_filter *filter) { @@ -455,3 +456,20 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype) die("Invalid filter type: %.*s", (int) len, cmd); } + +void gravatar_img(const char *email, size_t size) +{ + unsigned char sum[MD5_DIGEST_LENGTH]; + + if (email[0] == '<') + MD5((unsigned char *)email + 1, strlen(email) - 2, sum); + else + MD5((unsigned char *)email, strlen(email), sum); + + htmlf("<img src='//www.gravatar.com/avatar/" + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" + "?s=100&d=retro' alt='%s' width='%zu' height='%zu' >", + sum[0], sum[1], sum[2], sum[3], sum[4], sum[5], sum[6], sum[7], sum[8], + sum[9], sum[10], sum[11], sum[12], sum[13], sum[14], sum[15], + email, size, size); +} diff --git a/ui-log.c b/ui-log.c @@ -242,12 +242,8 @@ static void print_commit(struct commit *commit, struct rev_info *revs) show_commit_decorations(commit); html("</td><td>"); - char *tmp = strdup(info->author); - cgit_open_filter(ctx.repo->email_filter, info->author_email, "log"); + gravatar_img(info->author_email, 13); html_txt(info->author); - cgit_close_filter(ctx.repo->email_filter); - html_txt(tmp); - free(tmp); if (revs->graph) { html("</td><td>"); diff --git a/ui-shared.c b/ui-shared.c @@ -1138,9 +1138,7 @@ void cgit_print_pageheader(void) _html("<ul>") { _html("<li class='avatar'>") { - cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit"); - html_txt(info->committer); - cgit_close_filter(ctx.repo->email_filter); + gravatar_img(info->committer_email, 13); } html("</li>"); _html("<li class='commit-info'><ul>") {