From f53a6a49c684e3cd88d8bd4a6c207ac6ff012d45 Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Wed, 25 Sep 2024 15:33:51 +0000 Subject: new filters and update --- filters/email-libravatar-hover.lua | 42 ++++++++++++++++++++++++++++++++++++++ filters/email-libravatar-hover.py | 39 +++++++++++++++++++++++++++++++++++ filters/email-libravatar.lua | 0 filters/html-converters/md2html | 2 +- filters/owner-example.lua | 2 +- filters/syntax-highlighting.py | 4 ++-- 6 files changed, 85 insertions(+), 4 deletions(-) create mode 100755 filters/email-libravatar-hover.lua create mode 100755 filters/email-libravatar-hover.py mode change 100644 => 100755 filters/email-libravatar.lua (limited to 'filters') 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("" .. buffer) + return 0 +end + +-- Called when writing to the filter +function filter_write(str) + print("Filter Write:", str) -- Debug print + buffer = buffer .. str +end diff --git a/filters/email-libravatar-hover.py b/filters/email-libravatar-hover.py new file mode 100755 index 0000000..352122b --- /dev/null +++ b/filters/email-libravatar-hover.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +import sys +import hashlib +import codecs +import os + +# Read and process the email address from command line arguments +email = sys.argv[1].lower().strip() +if email[0] == '<': + email = email[1:] +if email[-1] == '>': + email = email[:-1] + +# Read the page argument (not used in this script but passed for compatibility) +page = sys.argv[2] + +# Ensure correct encoding for stdin and stdout +sys.stdin = codecs.getreader("utf-8")(sys.stdin.detach()) +sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) + +# Calculate MD5 hash of the email +md5 = hashlib.md5(email.encode()).hexdigest() + +# Read the standard input to get the buffer text +buffer = sys.stdin.read().strip() + +# Determine the base URL based on HTTPS environment variable +baseurl = "https://seccdn.libravatar.org/" if os.getenv("HTTPS") else "http://cdn.libravatar.org/" + +# Generate the HTML output with Libravatar images +html_output = ( + f"" + f"Libravatar" + f"Libravatar" + f" {buffer}" +) + +# Print the HTML output +print(html_output) diff --git a/filters/email-libravatar.lua b/filters/email-libravatar.lua old mode 100644 new mode 100755 diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html index 3f5aed7..627808a 100755 --- a/filters/html-converters/md2html +++ b/filters/html-converters/md2html @@ -307,7 +307,7 @@ div#cgit .markdown-body h1 a.toclink, div#cgit .markdown-body h2 a.toclink, div# sys.stdout.write(HtmlFormatter(style=dark_style).get_style_defs('.highlight')) sys.stdout.write(''' } - at media (prefers-color-scheme: light) { +@media (prefers-color-scheme: light) { ''') sys.stdout.write(HtmlFormatter(style=light_style).get_style_defs('.highlight')) sys.stdout.write(''' diff --git a/filters/owner-example.lua b/filters/owner-example.lua index 50fc25a..cb9fa7f 100644 --- a/filters/owner-example.lua +++ b/filters/owner-example.lua @@ -8,7 +8,7 @@ function filter_open() end function filter_close() - html(string.format("%s", "http://wiki.example.com/about/" .. buffer, buffer)) + html(string.format("%s", "http://wiki.surgot.tech/about/" .. buffer, buffer)) return 0 end diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py index 099e67b..f2c0fe1 100755 --- a/filters/syntax-highlighting.py +++ b/filters/syntax-highlighting.py @@ -54,9 +54,9 @@ except TypeError: # highlight! :-) # printout pygments' css definitions as well sys.stdout.write('') -- cgit v1.2.3-59-g8ed1b