added support for avatars

This commit is contained in:
scuti 2024-11-26 08:07:33 -08:00
parent a02033cc83
commit 4d9bb430d2

View File

@ -49,7 +49,38 @@ function get_short_date(timestamp)
)
end
function write_comments(pleroma_posts, instance)
function write_comments(pleroma_posts, instance, show_avatars)
show_avatars = show_avatars or false
function get_user(acct_data, instance, include_img)
-- user data
local user_info = ""
local result = ""
-- local uid = acct_data["id"]
-- local alias = acct_data["display_name"]
-- local handle = acct_data["acct"]
local vars = {
alias = acct_data["display_name"],
uid = acct_data["id"],
handle = acct_data["acct"],
}
if include_img then
user_info = [[
<figure>
<img src="$avatar$" loading="lazy" alt="avatar"/>
<figcaption>$alias$ <a href="$host$/users/$uid$">@$handle$</a> </figcaption>
</figure>
]]
vars.avatar = acct_data["avatar_static"]
result = user_info:gsub("%$(%w+)%$", vars)
else
user_info = "<p>$alias$ <a href=\"$host$/users/$uid$\">@$handle$</a></p>"
result = user_info:gsub("%$(%w+)%$", vars)
end
return result
end
if #pleroma_posts == 0 then
return ""
end
@ -58,7 +89,7 @@ function write_comments(pleroma_posts, instance)
<h3>
#$i$ <a href="$host$/notice/$pid$">$datetime$</a>
</h3>
<p>$alias$ <a href="$host$/users/$uid$">@$handle$</a></p>
$user$
<blockquote>
$text$
</blockquote>
@ -69,18 +100,14 @@ function write_comments(pleroma_posts, instance)
for i, post in ipairs(replies) do
local pid = post["id"]
local datetime = get_short_date(post["created_at"])
local uid = post["account"]["id"]
local alias = post["account"]["display_name"]
local handle = post["account"]["acct"]
local text = post["content"]
local interpolated = template:gsub("%$(%w+)%$", {
i= #replies - i + 1,
host=instance,
pid=pid,
datetime=datetime,
uid = uid,
handle = handle,
alias=alias,
user=get_user(post["account"], instance, true),
text = text
})
-- print(interpolated)
@ -138,7 +165,8 @@ function Meta(meta)
local host = ""
-- for each listed url in "pleroma-urls"
for _, v in pairs(pleroma_urls) do
local link, host, id = get_url_from_pandoc_str(v)
local link, domain, id = get_url_from_pandoc_str(v)
host = domain
table.insert(hrefs,
{link = link, id = id}
)