mirror of
https://notabug.org/scuti/pleroma-comments
synced 2024-12-22 19:09:45 +05:30
works - operates on one url
This commit is contained in:
parent
13255151a0
commit
86d397b548
@ -11,15 +11,6 @@ function tokenizeString(inputString, delimiter)
|
|||||||
return tokens
|
return tokens
|
||||||
end
|
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)
|
function get(link)
|
||||||
local args = {
|
local args = {
|
||||||
"-qO-",
|
"-qO-",
|
||||||
@ -45,25 +36,38 @@ function short_date(timestamp)
|
|||||||
return os.date("%a, %B %d, %Y", epoch)
|
return os.date("%a, %B %d, %Y", epoch)
|
||||||
end
|
end
|
||||||
|
|
||||||
function write_comments(pleroma_posts)
|
function write_comments(pleroma_posts, instance)
|
||||||
local template = [[
|
local template = [[
|
||||||
$datetime$
|
<h4 class="pleroma-comment">
|
||||||
$alias$
|
<a href="$host$/notice/$pid$">$datetime$</a>
|
||||||
$text$
|
</h4>
|
||||||
|
<a href="$host$/users/$uid$" class="pleroma-user">$alias$</a>
|
||||||
|
<blockquote>
|
||||||
|
$text$
|
||||||
|
</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 datetime = short_date(post["created_at"])
|
local datetime = short_date(post["created_at"])
|
||||||
|
local uid = post["account"]["id"]
|
||||||
local alias = post["account"]["acct"]
|
local alias = post["account"]["acct"]
|
||||||
local text = post["pleroma"]["content"]["text/plain"]
|
local text = post["pleroma"]["content"]["text/plain"]
|
||||||
local interpolated = template:gsub("%$(%w+)%$", {
|
local interpolated = template:gsub("%$(%w+)%$", {
|
||||||
|
host=instance,
|
||||||
|
pid=pid,
|
||||||
datetime=datetime,
|
datetime=datetime,
|
||||||
|
uid = uid,
|
||||||
alias = alias,
|
alias = alias,
|
||||||
text = text
|
text = text
|
||||||
})
|
})
|
||||||
print(interpolated)
|
-- print(interpolated)
|
||||||
|
table.insert(
|
||||||
|
comments, pandoc.RawBlock("html", interpolated)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
-- print(comments)
|
||||||
return comments
|
return comments
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -74,9 +78,15 @@ function Meta(meta)
|
|||||||
if elem == nil then
|
if elem == nil then
|
||||||
return -- abort
|
return -- abort
|
||||||
end
|
end
|
||||||
local s = pandoc.utils.stringify(elem)
|
local str = pandoc.utils.stringify(elem)
|
||||||
local url = get_api_link(s)
|
local tokens = tokenizeString(str, '/')
|
||||||
write_comments(get(url))
|
-- 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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user