FANDOM


--<nowiki>
local p = {}
 
local relativeEpisode = require('Module:TabSwitch')._relativeEpisode
local title = mw.title.getCurrentTitle()
local pageType
local episode
 
local function readableTitle(_title) 
    return _title:gsub(' %b()', '')
end
 
-- Creates the actual link for p.nextLink and p.prevLink methods
 
local function createLink(_episode)
    if pageType == 'Episode' then
        return '"[[' .. readableTitle(_episode) .. ']]"'
    else
        return '"[[' .. _episode .. '/' .. pageType .. '|' .. readableTitle(_episode) .. ']]"'
    end
end
 
-- Creates a link to the previous episode/gallery/transcript page
-- Returns empty string if wrong pagetype
-- Returns "N/A" if the previous episode is not known
 
local function prevLink(episodeTitle)
    if not pageType then return '' end
    local prevEpisode = relativeEpisode(episodeTitle, -1)
    if prevEpisode == 'N/A' then
        return 'N/A'
    else
        return createLink(prevEpisode)
    end
end
 
-- Creates a link to the next episode/gallery/transcript page
-- Returns empty string if wrong pagetype
-- Returns "N/A" if the next episode is not known
 
local function nextLink(episodeTitle)
    if not pageType then return '' end
    local nextEpisode = relativeEpisode(episodeTitle, 1)
    if nextEpisode == 'N/A' then
        return 'N/A'
    else
        return createLink(nextEpisode)
    end
end
 
function p.main()
    -- pageType =
    -- "Episode" on episode pages,
    -- "Gallery" on gallery pages,
    -- "Transcript" on transcript pages
    if title.namespace ~= 0 then
        return
    end
    if title.text == title.baseText then
        pageType = 'Episode'
    else
        pageType = title.subpageText
    end
    -- Get the current episode name based on the pagename
    -- Returns empty string if wrong pagetype
    if pageType then
        episode = readableTitle(title.baseText)
    else
        episode = ''
    end
    return episode .. ';' .. prevLink(title.baseText) .. ';' .. nextLink(title.baseText)
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.