Module:කර්තෘ සබැඳිය


--[=[
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*Author:([^|]-)|?%]%]", function (target)
		return "[[Author:" .. target .. "|" .. target .. "]]"
	end)
	
	-- auto-strip bracketed dates
	str = string.gsub(str, "^((.*) +%([0-9]+[-–][0-9]+%))$", function (full_target, no_date)
		return "[[Author:" .. 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 "[[Author:" .. str .. "]]"
	end
	
	-- make our own piped link
	return "[[Author:" .. str .. "|" .. str .. "]]"
end

return p