all repos — cgit @ v1.2.2

a hyperfast web frontend for git written in c

filters/email-libravatar.lua (view raw)

 1-- This script may be used with the email-filter or repo.email-filter settings in cgitrc.
 2-- It adds libravatar icons to author names. It is designed to be used with the lua:
 3-- prefix in filters.
 4--
 5-- Requirements:
 6-- 	luaossl
 7-- 	<http://25thandclement.com/~william/projects/luaossl.html>
 8--
 9
10local digest = require("openssl.digest")
11
12function md5_hex(input)
13	local b = digest.new("md5"):final(input)
14	local x = ""
15	for i = 1, #b do
16		x = x .. string.format("%.2x", string.byte(b, i))
17	end
18	return x
19end
20
21function filter_open(email, page)
22	buffer = ""
23	md5 = md5_hex(email:sub(2, -2):lower())
24end
25
26function filter_close()
27	baseurl = os.getenv("HTTPS") and "https://seccdn.libravatar.org/" or "http://cdn.libravatar.org/"
28	html("<img src='" .. baseurl .. "avatar/" .. md5 .. "?s=13&amp;d=retro' width='13' height='13' alt='Libravatar' /> " .. buffer)
29	return 0
30end
31
32function filter_write(str)
33	buffer = buffer .. str
34end
35
36