Module:Firehose links

From PickiPedia: A knowledge base of bluegrass, old time psychedelic jams, and other public domain music
Jump to navigationJump to search

Documentation for this module may be created at Module:Firehose links/doc

-- Helpers for Template:Firehose.
--
-- The firehose runs its #ask with link=none, because Semantic MediaWiki
-- otherwise hands the template a pre-rendered link for every value, which
-- defeats both #titleparts and any attempt to relabel the episode link.
--
-- The cost of link=none is that topic names arrive as plain text, comma-joined
-- when an episode has more than one. Linking that string whole would produce a
-- single broken redlink -- one link containing "Sam Bush, Jerry Douglas" -- so
-- split it and link each name on its own. Linking topics is the point of the
-- exercise: it is what puts an episode on the page of every person, band or
-- place it is about.
--
-- Note for future editors: do not wrap this header in a --[==[ ]==] block
-- comment containing wiki link syntax. Lua reads the inner brackets as nested
-- long brackets and refuses to load the module.

local p = {}

-- Values the title parser sometimes yields that are not entities, and so
-- should be shown but never linked.
local NOT_AN_ENTITY = {
	["and more"] = true,
	["more"] = true,
	["etc"] = true,
	["etc."] = true,
}

function p.topiclinks( frame )
	local raw = frame.args[1] or ""
	if raw:match( "^%s*$" ) then
		return ""
	end

	local out = {}
	for name in ( raw .. "," ):gmatch( "%s*(.-)%s*," ) do
		if name ~= "" then
			if NOT_AN_ENTITY[ name:lower() ] then
				table.insert( out, name )
			else
				table.insert( out, "[[" .. name .. "]]" )
			end
		end
	end

	return table.concat( out, ", " )
end

-- Former name, kept so an older revision of a calling template does not break.
p.guestlinks = p.topiclinks

return p