diff --git a/pleroma-comments.lua b/pleroma-comments.lua index ac5513e..3a143fb 100644 --- a/pleroma-comments.lua +++ b/pleroma-comments.lua @@ -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$ -$text$ +
+ $text$ +]] 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