included cards in comments if any

This commit is contained in:
scuti 2024-11-27 20:25:13 -08:00
parent 05ea67e03d
commit 174f25f12c

View File

@ -56,10 +56,6 @@ function write_comments(pleroma_posts, instance, show_avatars)
-- user data -- user data
local user_info = "" local user_info = ""
local result = "" local result = ""
-- local uid = acct_data["id"]
-- local alias = acct_data["display_name"]
-- local handle = acct_data["acct"]
local vars = { local vars = {
alias = acct_data["display_name"], alias = acct_data["display_name"],
uid = acct_data["id"], uid = acct_data["id"],
@ -81,6 +77,37 @@ function write_comments(pleroma_posts, instance, show_avatars)
return result return result
end end
function get_card(card, instance)
if card == nil or type(card) ~= "table" then
return ""
end
if card["provider_url"] == instance then
-- skip rendering a card
return ""
end
-- print(type(card))
local card_template = [[
<article class="card">
<header>
<h1 class="card-title">$title$</h1>
<p class="card-description">$description$</p>
</header>
<!-- <img src="$image$" alt="$image_description$" class="card-image" loading="lazy"/> -->
<footer>
<a href="$link$" class="card-link">Read More</a>
</footer>
</article>
]]
local vars = {
title = card["title"],
description = card["description"],
image = card["image"],
image_description=card["image_description"],
link = card["url"]
}
return card_template:gsub("%$(%w+)%$", vars)
end
if #pleroma_posts == 0 then if #pleroma_posts == 0 then
return "" return ""
end end
@ -93,6 +120,7 @@ function write_comments(pleroma_posts, instance, show_avatars)
<blockquote> <blockquote>
$text$ $text$
</blockquote> </blockquote>
$card$
</article> </article>
]] ]]
local comments = {} local comments = {}
@ -108,7 +136,8 @@ function write_comments(pleroma_posts, instance, show_avatars)
pid=pid, pid=pid,
datetime=datetime, datetime=datetime,
user=get_user(post["account"], instance, true), user=get_user(post["account"], instance, true),
text = text text = text,
card = get_card(post["card"], instance)
}) })
-- print(interpolated) -- print(interpolated)
table.insert( table.insert(