Module:BookSwitch

-- local p = {}

local bookData = mw.loadData('Module:BookSwitch/data') function p.bookFormat(frame) local tArgs = frame.args

-- get the arguments from parent of frame object -- if the module was invoked through an intermediate template if frame:getParent and frame:getParent.args[1] then tArgs = frame:getParent.args end

local book = tArgs[1] or "" local bold = (tArgs[2] and tArgs[2] ~= "")

-- Split the book name at ":" or "-" into Show and Subtitle local fakeShow, subtitle = mw.ustring.match(book,                   "^%s*([^%:%-]-)%s*[%:%-]%s*(.-)%s*$")

-- If ':' or '-' not in book name -- then subtitle is whole book name if not subtitle then subtitle = mw.ustring.gsub(book, "^%s*(.-)%s*$", "%1") end

-- default values local show = "Arrowverse Wiki" local year = "Arrowverse Wiki" local mid = ": "

if bookData[subtitle] then show = bookData[subtitle][1] year = bookData[subtitle][2] -- use separator if defined in bookData -- or use default value mid = bookData[subtitle][3] or ": " end

local fulltitle = show .. mid .. subtitle

-- if Show Name is included in Book Name but -- is not equal to show name from bookData if fakeShow and fakeShow ~= show then year = "Arrowverse Wiki" end

if show == "S.T.A.R. Labs" or show == "The Flash" then show="The Flash (The CW)" end

local hoverArgs = {} local extra = ""

if year == "Arrowverse Wiki" then hoverArgs = { subtitle, subtitle, subtitle .. " (Arrowverse Wiki)" }       extra = "" elseif bold then hoverArgs = { fulltitle, subtitle, fulltitle .. " (" .. year .. ")", color = "#" .. frame:expandTemplate{ title = "ColorSwitch", args = {series = show}} }   else hoverArgs = { fulltitle, fulltitle, fulltitle .. " (" .. year .. ")" }   end return frame:expandTemplate{ title = "Hoverlink", args = hoverArgs } .. extra end return p --