diff options
Diffstat (limited to 'filters')
-rwxr-xr-x | filters/email-libravatar-hover.lua | 42 | ||||
-rwxr-xr-x | filters/email-libravatar-hover.py | 39 | ||||
-rwxr-xr-x[-rw-r--r--] | filters/email-libravatar.lua | 0 | ||||
-rwxr-xr-x | filters/html-converters/md2html | 2 | ||||
-rw-r--r-- | filters/owner-example.lua | 2 | ||||
-rwxr-xr-x | filters/syntax-highlighting.py | 4 |
6 files changed, 85 insertions, 4 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 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"<span class='libravatar'>" + f"<img class='inline' src='{baseurl}avatar/{md5}?s=13&d=retro' width='13' height='13' alt='Libravatar' />" + f"<img class='onhover' src='{baseurl}avatar/{md5}?s=128&d=retro' width='128' height='128' alt='Libravatar' />" + f"</span> {buffer}" +) + +# Print the HTML output +print(html_output) diff --git a/filters/email-libravatar.lua b/filters/email-libravatar.lua index 7336baf..7336baf 100644..100755 --- a/filters/email-libravatar.lua +++ b/filters/email-libravatar.lua 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("<a href=\"%s\">%s</a>", "http://wiki.example.com/about/" .. buffer, buffer)) + html(string.format("<a href=\"%s\">%s</a>", "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('<style>') -sys.stdout.write('\n at media only all and (prefers-color-scheme: dark) {\n') +sys.stdout.write('\n@media only all and (prefers-color-scheme: dark) {\n') sys.stdout.write(dark_formatter.get_style_defs('.highlight')) -sys.stdout.write('\n}\n at media (prefers-color-scheme: light) {\n') +sys.stdout.write('\n}\n@media (prefers-color-scheme: light) {\n') sys.stdout.write(light_formatter.get_style_defs('.highlight')) sys.stdout.write('\n}\n') sys.stdout.write('</style>') |