diff options
author | Biswakalyan Bhuyan <biswa@surgot.in> | 2024-09-25 15:33:51 +0000 |
---|---|---|
committer | Biswakalyan Bhuyan <biswa@surgot.tech> | 2024-09-25 15:37:31 +0000 |
commit | f53a6a49c684e3cd88d8bd4a6c207ac6ff012d45 (patch) | |
tree | 5f59e7d6580215803ea9cc4e0925794bcbae3dcc /filters/email-libravatar-hover.lua | |
parent | 6fa71c7efadb990aad14d1c6a7833e9cae88436d (diff) | |
download | cgit-master.tar.gz cgit-master.tar.bz2 cgit-master.zip |
Diffstat (limited to 'filters/email-libravatar-hover.lua')
-rwxr-xr-x | filters/email-libravatar-hover.lua | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/filters/email-libravatar-hover.lua b/filters/email-libravatar-hover.lua new file mode 100755 index 0000000..f94a980 --- /dev/null +++ b/filters/email-libravatar-hover.lua @@ -0,0 +1,42 @@ +#!/usr/bin/env luajit51 +local digest = require("openssl.digest") + +-- Function to calculate MD5 hash of the input +function md5_hex(input) + print("Calculating MD5 for:", input) -- Debug print + local b = digest.new("md5"):final(input) + local x = "" + for i = 1, #b do + x = x .. string.format("%.2x", string.byte(b, i)) + end + print("MD5 Hash:", x) -- Debug print + return x +end + +-- Called when the filter opens +function filter_open(email, page) + print("Filter Open. Email:", email) -- Debug print + buffer = "" + hexdigest = md5_hex(email:sub(2, -2):lower()) + print("Hex Digest:", hexdigest) -- Debug print +end + +-- Called when the filter closes +function filter_close() + local baseurl = os.getenv("HTTPS") and "https://seccdn.libravatar.org/" or "http://cdn.libravatar.org/" + print("Base URL:", baseurl) -- Debug print + print("Hex Digest in filter_close:", hexdigest) -- Debug print + local avatar_url_small = baseurl .. "avatar/" .. hexdigest .. "?s=13&d=retro" + local avatar_url_large = baseurl .. "avatar/" .. hexdigest .. "?s=128&d=retro" + print("Avatar URL Small:", avatar_url_small) -- Debug print + print("Avatar URL Large:", avatar_url_large) -- Debug print + + html("<span class='libravatar'><img class='inline' src='" .. avatar_url_small .. "' /><img class='onhover' src='" .. avatar_url_large .. "' /></span>" .. buffer) + return 0 +end + +-- Called when writing to the filter +function filter_write(str) + print("Filter Write:", str) -- Debug print + buffer = buffer .. str +end |