ਮੌਡਿਊਲ:Author link
ਦਿੱਖ
Documentation for this module may be created at ਮੌਡਿਊਲ:Author link/doc
--[=[
Helper functons to construct author links
]=]
local p = {} --p stands for package
-- construct an author link from a given string
function p.constructAuthorLink(str)
-- strip "Portal:" prefixes if not piped
str = string.gsub(str, "%[%[%s*Portal:([^|]-)|?%]%]", function (target)
return "[[Portal:" .. target .. "|" .. target .. "]]"
end)
-- And for authors
str = string.gsub(str, "%[%[%s*ਲੇਖਕ:([^|]-)|?%]%]", function (target)
return "[[ਲੇਖਕ:" .. target .. "|" .. target .. "]]"
end)
-- auto-strip bracketed dates
str = string.gsub(str, "^((.*) +%([0-9]+[-–][0-9]+%))$", function (full_target, no_date)
return "[[ਲੇਖਕ:" .. full_target .. "|" .. no_date .. "]]"
end, 1)
-- if the string has its own links, return it now
if string.match(str, "%[%[") then
return str
end
if string.match(str, "[uU]nknown") then
return "[[Portal:Anonymous texts|Anonymous]]"
end
if string.match(str, "[vV]arious") then
return "Various"
end
-- if a pipe is provided
if string.match(str, "|") then
return "[[ਲੇਖਕ:" .. str .. "]]"
end
-- make our own piped link
return "[[ਲੇਖਕ:" .. str .. "|" .. str .. "]]"
end
return p