mirror of
https://notabug.org/scuti/pleroma-comments
synced 2024-12-22 19:09:45 +05:30
export number of replies, sort replies newest first
This commit is contained in:
parent
50dc454443
commit
173e4f5947
@ -44,27 +44,32 @@ end
|
|||||||
|
|
||||||
function write_comments(pleroma_posts, instance)
|
function write_comments(pleroma_posts, instance)
|
||||||
local template = [[
|
local template = [[
|
||||||
<h4 class="pleroma-comment">
|
<article class="pleroma-comment" id="pleroma-comment$i$">
|
||||||
<a href="$host$/notice/$pid$">$datetime$</a>
|
<h3>
|
||||||
</h4>
|
#$i$ <a href="$host$/notice/$pid$">$datetime$</a>
|
||||||
<a href="$host$/users/$uid$" class="pleroma-user">$alias$</a>
|
</h3>
|
||||||
|
<p>$alias$ <a href="$host$/users/$uid$">@$handle$</a></p>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
$text$
|
$text$
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
</article>
|
||||||
]]
|
]]
|
||||||
local comments = {}
|
local comments = {}
|
||||||
local replies = pleroma_posts-- ["descendants"]
|
local replies = pleroma_posts-- ["descendants"]
|
||||||
for _, post in ipairs(replies) do
|
for i, 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"])
|
||||||
local uid = post["account"]["id"]
|
local uid = post["account"]["id"]
|
||||||
local alias = post["account"]["acct"]
|
local alias = post["account"]["display_name"]
|
||||||
|
local handle = 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+)%$", {
|
||||||
|
i= #replies - i + 1,
|
||||||
host=instance,
|
host=instance,
|
||||||
pid=pid,
|
pid=pid,
|
||||||
datetime=datetime,
|
datetime=datetime,
|
||||||
uid = uid,
|
uid = uid,
|
||||||
|
handle = handle,
|
||||||
alias=alias,
|
alias=alias,
|
||||||
text = text
|
text = text
|
||||||
})
|
})
|
||||||
@ -92,14 +97,18 @@ function Meta(meta)
|
|||||||
return -- abort
|
return -- abort
|
||||||
end
|
end
|
||||||
local all_replies = {}
|
local all_replies = {}
|
||||||
|
local newelem = {}
|
||||||
local host = ""
|
local host = ""
|
||||||
for _, v in pairs(elem) do
|
for _, v in pairs(elem) do
|
||||||
local str = pandoc.utils.stringify(v)
|
local str = pandoc.utils.stringify(v)
|
||||||
print(str)
|
print(str)
|
||||||
local tokens = tokenizeString(str, '/')
|
|
||||||
-- 1 = protocol, 2 = host ...
|
-- 1 = protocol, 2 = host ...
|
||||||
-- https://host.tld/notice/12345
|
-- https://host.tld/notice/12345
|
||||||
|
local tokens = tokenizeString(str, '/')
|
||||||
local id = tokens[#tokens]
|
local id = tokens[#tokens]
|
||||||
|
table.insert(newelem,
|
||||||
|
{link = str, id = id}
|
||||||
|
)
|
||||||
host = tokens[2]
|
host = tokens[2]
|
||||||
local url = "https://" .. host .. "/api/v1/statuses/" .. id .. "/context"
|
local url = "https://" .. host .. "/api/v1/statuses/" .. id .. "/context"
|
||||||
local got = get(url)
|
local got = get(url)
|
||||||
@ -113,10 +122,13 @@ function Meta(meta)
|
|||||||
function(a, b)
|
function(a, b)
|
||||||
local ta = get_epoch_time(a["created_at"])
|
local ta = get_epoch_time(a["created_at"])
|
||||||
local tb = get_epoch_time(b["created_at"])
|
local tb = get_epoch_time(b["created_at"])
|
||||||
return ta < tb
|
return ta > tb
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
meta["comments"] = write_comments(all_replies, "https://" .. host)
|
local c = write_comments(all_replies, "https://" .. host)
|
||||||
|
meta["pleroma-comments"] = c
|
||||||
|
meta["pleroma-comments-count"] = #c
|
||||||
|
meta["pleroma"] = newelem
|
||||||
return meta
|
return meta
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user