works - operates on one url

This commit is contained in:
antares 2024-07-07 01:22:00 -07:00
parent 13255151a0
commit 86d397b548

View File

@ -11,15 +11,6 @@ function tokenizeString(inputString, delimiter)
return tokens
end
function get_api_link(str)
local tokens = tokenizeString(str, '/')
-- 1 = protocol, 2 = host ...
-- https://host.tld/notice/12345
local id = tokens[#tokens]
local host = tokens[2]
return "https://" .. host .. "/api/v1/statuses/" .. id .. "/context"
end
function get(link)
local args = {
"-qO-",
@ -45,25 +36,38 @@ function short_date(timestamp)
return os.date("%a, %B %d, %Y", epoch)
end
function write_comments(pleroma_posts)
function write_comments(pleroma_posts, instance)
local template = [[
$datetime$
$alias$
<h4 class="pleroma-comment">
<a href="$host$/notice/$pid$">$datetime$</a>
</h4>
<a href="$host$/users/$uid$" class="pleroma-user">$alias$</a>
<blockquote>
$text$
</blockquote>
]]
local comments = {}
local replies = pleroma_posts["descendants"]
for _, post in ipairs(replies) do
local pid = post["id"]
local datetime = short_date(post["created_at"])
local uid = post["account"]["id"]
local alias = post["account"]["acct"]
local text = post["pleroma"]["content"]["text/plain"]
local interpolated = template:gsub("%$(%w+)%$", {
host=instance,
pid=pid,
datetime=datetime,
uid = uid,
alias = alias,
text = text
})
print(interpolated)
-- print(interpolated)
table.insert(
comments, pandoc.RawBlock("html", interpolated)
)
end
-- print(comments)
return comments
end
@ -74,9 +78,15 @@ function Meta(meta)
if elem == nil then
return -- abort
end
local s = pandoc.utils.stringify(elem)
local url = get_api_link(s)
write_comments(get(url))
local str = pandoc.utils.stringify(elem)
local tokens = tokenizeString(str, '/')
-- 1 = protocol, 2 = host ...
-- https://host.tld/notice/12345
local id = tokens[#tokens]
local host = tokens[2]
local url = "https://" .. host .. "/api/v1/statuses/" .. id .. "/context"
meta["comments"] = write_comments(get(url), "https://" .. host)
return meta
end