Mercurial > self-hosted
comparison CGIT/filters/email-libravatar-korg.lua @ 3:8e515a52c7a9
add:Cgit File
| author | Pluto <meokcin@gmail.com> |
|---|---|
| date | Tue, 03 Sep 2024 17:14:28 +0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 2:c8c80b5286b1 | 3:8e515a52c7a9 |
|---|---|
| 1 -- This script may be used with the email-filter or repo.email-filter settings in cgitrc. | |
| 2 -- It adds gravatar icons to author names. It is designed to be used with the lua: | |
| 3 -- prefix in filters. It is much faster than the corresponding python script. | |
| 4 -- | |
| 5 -- Requirements: | |
| 6 -- luaossl | |
| 7 -- <http://25thandclement.com/~william/projects/luaossl.html> | |
| 8 -- | |
| 9 | |
| 10 local digest = require("openssl.digest") | |
| 11 | |
| 12 function 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 | |
| 19 end | |
| 20 | |
| 21 function filter_open(email, page) | |
| 22 buffer = "" | |
| 23 md5 = md5_hex(email:sub(2, -2):lower()) | |
| 24 end | |
| 25 | |
| 26 function filter_close() | |
| 27 html("<span class='libravatar'>" .. | |
| 28 "<img class='inline' src='//www.gravatar.com/avatar/" .. md5 .. "?s=13&d=retro' />" .. | |
| 29 "<img class='onhover' src='//www.gravatar.com/avatar/" .. md5 .. "?s=128&d=retro' />" .. | |
| 30 "</span>" .. buffer) | |
| 31 return 0 | |
| 32 end | |
| 33 | |
| 34 function filter_write(str) | |
| 35 buffer = buffer .. str | |
| 36 end |
