From 8d203094d1f39805670574ddc97ffb3d97497bf8 Mon Sep 17 00:00:00 2001 From: memdmp Date: Wed, 15 Jan 2025 12:46:50 +0100 Subject: feat: nicen up the repo for estrogen.zone --- image/filters/email-libravatar.lua | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 image/filters/email-libravatar.lua (limited to 'image/filters/email-libravatar.lua') diff --git a/image/filters/email-libravatar.lua b/image/filters/email-libravatar.lua new file mode 100644 index 0000000..5e8554e --- /dev/null +++ b/image/filters/email-libravatar.lua @@ -0,0 +1,56 @@ +-- 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 sha256_hex(input) + local b = digest.new('sha256'):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 = '' + sha256 = sha256_hex(email:sub(2, -2):lower()) +end + +function filter_close() + baseurl = not os.getenv('FORCE_HTTP') and 'https://seccdn.libravatar.org/' or 'http://cdn.libravatar.org/' + local url = baseurl .. 'avatar/' .. sha256 .. '?d=retro&s=' + local rng = tostring(math.random(0, 10000000)) + -- very bad email obfuscation + html( + '\'Libravatar\'\'Large ' + .. buffer:gsub('@', ''):gsub('%.', '') + .. '' + .. ( + math.random(0, 1000) < 777 + and '' + or '' + ) + ) + return 0 +end + +function filter_write(str) + buffer = buffer .. str +end -- cgit v1.2.3