From 0cdc688555ea07bee362f76b9ce610b1801340af Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Thu, 18 Mar 2021 17:54:47 -0400 Subject: Initial commit --- email-libravatar.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 email-libravatar.lua (limited to 'email-libravatar.lua') diff --git a/email-libravatar.lua b/email-libravatar.lua new file mode 100644 index 0000000..7d378fd --- /dev/null +++ b/email-libravatar.lua @@ -0,0 +1,37 @@ +-- 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) + html("Libravatar" .. buffer) + return 0 +end + +function filter_write(str) + buffer = buffer .. str +end + + -- cgit v1.2.3