set directory for avatars in config.lua

This commit is contained in:
scuti 2024-12-06 15:56:58 -08:00
parent 4ab3993fa8
commit 799e7ae0bd

View File

@ -1,8 +1,27 @@
-- can't resolve seggfault on luasec, luasocket'
-- local https = "wget"
local json = require("cjson")
pleroma_avatar_save_path = nil -- location of downloaded images
pleroma_avatar_path = nil -- prepended to image file, written on page
-- to configure, put above vars in a file named 'config.lua'
pcall(
function ()
dofile("config.lua")
end
)
--[[
if these variables are still `nil` after `dofile()` then
the script will look for it in the yaml header.
note: lua filters can not access variables defined on the command line,
e.g `pandoc -V foo="bar"`
and it may not be ideal to define paths in yaml headers,
i.e changing the path for avatars on a website would involve editing each
manuscript.
]]--
-- for testing
function printTable(t)
if t then
@ -347,17 +366,22 @@ function Meta(meta)
return -- abort
end
-- if both are defined, then do not hotlink avatars
if not pleroma_avatar_save_path then
pleroma_avatar_save_path = meta["pleroma-avatar-save-path"]
end
if not pleroma_avatar_path then
pleroma_avatar_path = meta["pleroma-avatar-path"]
end
-- most servers appear to serve hotilnked avatars however
-- images will be missing in case of downtime or shutdown
local is_hotlink = true
-- where to save downloaded avatars
local pleroma_avatar_save_path = meta["pleroma-avatar-save-path"]
-- (page) path written on the page-
local pleroma_avatar_path = meta["pleroma-avatar-path"]
-- if both are defined, then do not hotlink avatars
if pleroma_avatar_save_path and pleroma_avatar_path then
is_hotlink = false
end
-- OR a user has changed their avatar and the old avatar gets deleted
-- var currently unused
-- local is_hotlink = true
-- if pleroma_avatar_save_path and pleroma_avatar_path then
-- is_hotlink = false
-- end
local all_replies = {}
local hrefs = {}
@ -385,11 +409,9 @@ function Meta(meta)
local c, i, l = write_comments(
all_replies,
"https://" .. host,
"images/avatars/"
pleroma_avatar_path
)
printTable(i)
printTable(l)
get_images(i, l, "test/images/avatars/")
get_images(i, l, pleroma_avatar_save_path)
meta["pleroma-comments"] = c
meta["pleroma-comments-count"] = #c
meta["pleroma-has-comments"] = (#c > 0)