Module documentation

This module has various functions described below and should only be utilized on templates. To call a module in a template, insert {{#invoke:BookSwitch|function name|various parameters}} onto the template.[ Data ]

For help on this module, please contact an administrator.
Visit Module:BookSwitch/doc to edit this text! (How does this work?)

--[[Category:Lua modules]]
local p = {}
local bookData = mw.loadData('Module:BookSwitch/data')
 
function p.bookFormat(frame)
    local book= frame.args[1]
    local bold=frame.args[2]
    local length= mw.ustring.len(book)
    local par={}
    if mw.ustring.find(book,':',1,true)==nil
        then if mw.ustring.find(book,'-',1,true)==nil
            then par=1
            else par=mw.ustring.find(book,'-',1,true)+2
            end
        else par=mw.ustring.find(book,':',1,true)+2
    end
    local subtitle=mw.ustring.sub(book,par,length)
    local show="Arrowverse Wiki"
    local year="Arrowverse Wiki"
    local mid={}
    if bookData[subtitle]
        then show=bookData[subtitle][1]
            year=bookData[subtitle][2]
            mid=bookData[subtitle][3] or ": "
    end
    local fulltitle = show
    ..mid
    ..subtitle
    
    if par>1
        then local fakeShow=mw.ustring.sub(book,1,par-3)
            if show==fakeShow
            then year=year
            else fakeShow=mw.ustring.sub(book,1,par-4)
                if show==fakeShow
                then year=year
                else year="Arrowverse Wiki"
                end
            end
    end
    if show=="S.T.A.R. Labs" or show=="The Flash"
        then show="The Flash (The CW)"
    end
    local hoverInfo={}
    if year=="Arrowverse Wiki"
        then hoverInfo= "{{Hoverlink|"
                    ..subtitle
                    .."|"
                    ..subtitle
                    .."|"
                    ..subtitle
                    .." (Arrowverse Wiki)}}[["
                    .."Category:Broken Bk link|"
                    ..subtitle
                    .."]]"
            else if mw.ustring.len(bold)>0
                then hoverInfo= "{{Hoverlink|"
                    ..fulltitle
                    .."|"
                    ..subtitle
                    .."|"
                    ..fulltitle
                    .." ("
                    ..year
                    ..")|color=#{{ColorSwitch|series="
                    ..show
                    .."}}}}"
                else hoverInfo= "{{Hoverlink|"
                    ..fulltitle
                    .."|"
                    ..fulltitle
                    .."|"
                    ..fulltitle
                    .." ("
                    ..year
                    ..")}}"
                end
    end
    return frame:preprocess(hoverInfo)
end
return p
Community content is available under CC-BY-SA unless otherwise noted.