Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Collect an email filter's writes like the others
Diffstat (limited to '')
| -rw-r--r-- | custom/extensions/email-gravatar.lua | 11 | |
| -rw-r--r-- | custom/extensions/email-libravatar.lua | 11 |
2 files changed, 12 insertions, 10 deletions
diff --git a/custom/extensions/email-gravatar.lua b/custom/extensions/email-gravatar.lua index aebb27c..467deff 100644 --- a/custom/extensions/email-gravatar.lua +++ b/custom/extensions/email-gravatar.lua @@ -47,7 +47,7 @@ local base_url = "https://gravatar.com/avatar/" -- One name reaches this filter as an open, writes and a close, so what the -- open works out is kept here for the close. -local buffer = "" +local chunks = {} local avatar_hash = nil local function hash_hex(input) @@ -96,7 +96,7 @@ local function normalize_email(email) end function filter_open(email, page) - buffer = "" + chunks = {} local address = normalize_email(email) if address == nil or not has_digest then avatar_hash = nil @@ -106,7 +106,7 @@ function filter_open(email, page) end function filter_write(text) - buffer = buffer .. text + chunks[#chunks + 1] = text end local function avatar_url(size) @@ -118,14 +118,15 @@ end -- off the critical path. The icon only decorates the name beside it, so its -- alt text is empty and a screen reader goes straight to the name. function filter_close() + local text = table.concat(chunks) if avatar_hash == nil then - html(buffer) + html(text) else html("<img src='" .. avatar_url(avatar_size) .. "' srcset='" .. avatar_url(avatar_size * 2) .. " 2x" .. "' alt='' width='" .. avatar_size .. "' height='" .. avatar_size .. - "' loading='lazy' decoding='async'> " .. buffer) + "' loading='lazy' decoding='async'> " .. text) end return 0 end diff --git a/custom/extensions/email-libravatar.lua b/custom/extensions/email-libravatar.lua index fca67a7..0a6e10c 100644 --- a/custom/extensions/email-libravatar.lua +++ b/custom/extensions/email-libravatar.lua @@ -46,7 +46,7 @@ local base_url = "https://seccdn.libravatar.org/avatar/" -- One name reaches this filter as an open, writes and a close, so what the -- open works out is kept here for the close. -local buffer = "" +local chunks = {} local avatar_hash = nil local function hash_hex(input) @@ -95,7 +95,7 @@ local function normalize_email(email) end function filter_open(email, page) - buffer = "" + chunks = {} local address = normalize_email(email) if address == nil or not has_digest then avatar_hash = nil @@ -105,7 +105,7 @@ function filter_open(email, page) end function filter_write(text) - buffer = buffer .. text + chunks[#chunks + 1] = text end local function avatar_url(size) @@ -117,14 +117,15 @@ end -- off the critical path. The icon only decorates the name beside it, so its -- alt text is empty and a screen reader goes straight to the name. function filter_close() + local text = table.concat(chunks) if avatar_hash == nil then - html(buffer) + html(text) else html("<img src='" .. avatar_url(avatar_size) .. "' srcset='" .. avatar_url(avatar_size * 2) .. " 2x" .. "' alt='' width='" .. avatar_size .. "' height='" .. avatar_size .. - "' loading='lazy' decoding='async'> " .. buffer) + "' loading='lazy' decoding='async'> " .. text) end return 0 end |
