works for multiple urls

This commit is contained in:
antares 2024-07-07 02:07:13 -07:00
parent baa9ebc17f
commit 50dc454443

View File

@ -53,7 +53,7 @@ function write_comments(pleroma_posts, instance)
</blockquote> </blockquote>
]] ]]
local comments = {} local comments = {}
local replies = pleroma_posts["descendants"] local replies = pleroma_posts-- ["descendants"]
for _, post in ipairs(replies) do for _, post in ipairs(replies) do
local pid = post["id"] local pid = post["id"]
local datetime = get_short_date(post["created_at"]) local datetime = get_short_date(post["created_at"])
@ -77,21 +77,46 @@ function write_comments(pleroma_posts, instance)
return comments return comments
end end
function combine_tables(a,b)
-- iterate through b, add to a
for i=1,#b do
table.insert(a, b[i])
end
return a
end
function Meta(meta) function Meta(meta)
local elem = meta["pleroma-urls"] local elem = meta["pleroma-urls"]
print(elem) -- print(elem)
if elem == nil then if elem == nil then
return -- abort return -- abort
end end
local str = pandoc.utils.stringify(elem) local all_replies = {}
local tokens = tokenizeString(str, '/') local host = ""
-- 1 = protocol, 2 = host ... for _, v in pairs(elem) do
-- https://host.tld/notice/12345 local str = pandoc.utils.stringify(v)
local id = tokens[#tokens] print(str)
local host = tokens[2] local tokens = tokenizeString(str, '/')
local url = "https://" .. host .. "/api/v1/statuses/" .. id .. "/context" -- 1 = protocol, 2 = host ...
meta["comments"] = write_comments(get(url), "https://" .. host) -- https://host.tld/notice/12345
local id = tokens[#tokens]
host = tokens[2]
local url = "https://" .. host .. "/api/v1/statuses/" .. id .. "/context"
local got = get(url)
if #all_replies == 0 then
all_replies = got["descendants"]
else
combine_tables(all_replies, got["descendants"])
end
end
table.sort(all_replies,
function(a, b)
local ta = get_epoch_time(a["created_at"])
local tb = get_epoch_time(b["created_at"])
return ta < tb
end
)
meta["comments"] = write_comments(all_replies, "https://" .. host)
return meta return meta
end end