diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2014-03-19 09:58:41 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2024-11-25 10:05:37 +0100 |
commit | f6a936de790be1d19a106ba845dd75fc2ba87399 (patch) | |
tree | 053588429f197f1ee6eedbc0287f6996a6e505f7 /filters | |
parent | bcc708c9789efe5d5a7f08ca41244cade989a42b (diff) | |
download | cgit-f6a936de790be1d19a106ba845dd75fc2ba87399.tar.gz cgit-f6a936de790be1d19a106ba845dd75fc2ba87399.tar.xz |
steal kernel.org's libravatar lua
Diffstat (limited to 'filters')
-rw-r--r-- | filters/email-libravatar-hover.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/filters/email-libravatar-hover.lua b/filters/email-libravatar-hover.lua new file mode 100644 index 0000000..c14b618 --- /dev/null +++ b/filters/email-libravatar-hover.lua @@ -0,0 +1,25 @@ +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 = "" + hexdigest = 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("<span class='libravatar'><img class='inline' src='" .. baseurl .. "avatar/" .. hexdigest .. "?s=13&d=retro' /><img class='onhover' src='" .. baseurl .. "avatar/" .. hexdigest .. "?s=128&d=retro' /></span>" .. buffer) + return 0 +end + +function filter_write(str) + buffer = buffer .. str +end |