-- 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