From 85016e706cd00e527dba3fa83b2783dfb56a4ffa Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 27 Dec 2020 18:45:04 -0500 Subject: Squashed 'www/git.causal.agency/cgit/' content from commit 02221fd3 git-subtree-dir: www/git.causal.agency/cgit git-subtree-split: 02221fd3fe523a3293d64e3359036e3a71d6fd7e --- filters/email-libravatar.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 filters/email-libravatar.lua (limited to 'filters/email-libravatar.lua') diff --git a/filters/email-libravatar.lua b/filters/email-libravatar.lua new file mode 100644 index 00000000..7336baf8 --- /dev/null +++ b/filters/email-libravatar.lua @@ -0,0 +1,36 @@ +-- This script may be used with the email-filter or repo.email-filter settings in cgitrc. +-- It adds libravatar icons to author names. It is designed to be used with the lua: +-- prefix in filters. +-- +-- Requirements: +-- luaossl +-- +-- + +local digest = require("openssl.digest") + +function md5_hex(input) + local b = digest.new("md5"):final(input) + local x = "" + for i = 1, #b do + x = x .. string.format("%.2x", string.byte(b, i)) + end + return x +end + +function filter_open(email, page) + buffer = "" + md5 = md5_hex(email:sub(2, -2):lower()) +end + +function filter_close() + baseurl = os.getenv("HTTPS") and "https://seccdn.libravatar.org/" or "http://cdn.libravatar.org/" + html("Libravatar " .. buffer) + return 0 +end + +function filter_write(str) + buffer = buffer .. str +end + + -- cgit 1.4.1