mirror of
https://notabug.org/scuti/pleroma-comments
synced 2024-12-22 19:09:45 +05:30
works for multiple urls
This commit is contained in:
parent
baa9ebc17f
commit
50dc454443
@ -53,7 +53,7 @@ function write_comments(pleroma_posts, instance)
|
||||
</blockquote>
|
||||
]]
|
||||
local comments = {}
|
||||
local replies = pleroma_posts["descendants"]
|
||||
local replies = pleroma_posts-- ["descendants"]
|
||||
for _, post in ipairs(replies) do
|
||||
local pid = post["id"]
|
||||
local datetime = get_short_date(post["created_at"])
|
||||
@ -77,21 +77,46 @@ function write_comments(pleroma_posts, instance)
|
||||
return comments
|
||||
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)
|
||||
local elem = meta["pleroma-urls"]
|
||||
print(elem)
|
||||
-- print(elem)
|
||||
if elem == nil then
|
||||
return -- abort
|
||||
end
|
||||
local str = pandoc.utils.stringify(elem)
|
||||
local all_replies = {}
|
||||
local host = ""
|
||||
for _, v in pairs(elem) do
|
||||
local str = pandoc.utils.stringify(v)
|
||||
print(str)
|
||||
local tokens = tokenizeString(str, '/')
|
||||
-- 1 = protocol, 2 = host ...
|
||||
-- https://host.tld/notice/12345
|
||||
local id = tokens[#tokens]
|
||||
local host = tokens[2]
|
||||
host = tokens[2]
|
||||
local url = "https://" .. host .. "/api/v1/statuses/" .. id .. "/context"
|
||||
meta["comments"] = write_comments(get(url), "https://" .. host)
|
||||
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
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user