Module:Ref
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Ref/doc
local p = {}
function StringAdd(base, content)
base = base .. content
end
function ContainsOr(base, options)
local found = false
for _, option in ipairs(options) do
if base == option then
found = true
break
end
end
return found
end
function p.main(frame)
local parent_args = frame:getParent().args
local final_content = ""
-- Variables from parent template.
-- Ref tag parameters.
local name = parent_args["name"]
local group = parent_args["group"] -- "lower-alpha" or nil mostly
-- MLA citation parameters.
local title = parent_args["title"]
local url = parent_args["url"]
local author = parent_args["author"]
local publisher = parent_args["publisher"]
local platform = parent_args["platform"]
local handle = parent_args["handle"]
local date = parent_args["date"]
local archived = parent_args["archived"]
local isbn = parent_args["isbn"]
-- Link platform-specific handles.
local handle_link = ""
if ContainsOr(platform, {"Twitter", "X", "twitter", "x"}) then
handle_link = "[https://twitter.com/@" .. handle .. " @" .. handle .. "]"
elseif ContainsOr(platform, {"YouTube", "youtube", "YT", "yt"}) then
handle_link = "[https://www.youtube.com/@" .. handle .. " @" .. handle .. "]"
end
if parent_args[1] then
final_content = parent_args[1]
else
if author then
StringAdd(final_content, author)
if handle then
StringAdd(final_content, " <nowiki>[</nowiki>" .. handle .. "]")
end
end
end
return frame:extensionTag{ name = "ref", content = final_content, args = { name = name, group = group }}
end
return p