FANDOM


(let's see if Doru can write a valid working code from the first try)
Line 21: Line 21:
 
-- Returns a string
 
-- Returns a string
 
local function readableTitle(_title)
 
local function readableTitle(_title)
return _title:gsub(' %b()', ''):gsub('/%a+')
+
return _title:gsub(' %b()', ''):gsub('/%a+', '')
 
end
 
end
   

Revision as of 14:22, November 12, 2017

-- <nowiki>
 
local p = {}
 
local relativeEpisode = require('Module:TabSwitch')._relativeEpisode
local title = mw.title.getCurrentTitle()
 
-- Checks if page has the postfix (short) in the title
-- Returns a boolean
local function isShort(ep)
    return ep:find('%(short%)') ~= nil
end
 
-- Checks if page has a postfix (episode) in the title
-- Returns a boolean
local function isEpisode(ep) 
    return ep:find('%(episode%)') ~= nil
end
 
-- Removes content between parentheses in titles
-- Returns a string
local function readableTitle(_title) 
    return _title:gsub(' %b()', ''):gsub('/%a+', '')
end
 
-- Creates a wikilink with the arguments provided
-- Returns a string
local function createLink(page, displayText)
    if displayText ~= page and displayText then
        return '[[' .. page .. '|' .. displayText .. ']]'
    else
        return '[[' .. page .. ']]'
    end
end
 
-- Utility function to provide easier way of calling createLink
-- Returns a string
local function createEpisodeLink(episode)
    return createLink(episode, readableTitle(episode))
end
 
-- Returns relative episode link from offset number
-- Returns a string
local function relativeLink(episode, offset)
    local relEpisode = relativeEpisod(episode, offset)
    if relEpisode == 'N/A' then
        return relEpisode
    else
        return createEpisodeLink(relEpisode)
    end
end
 
-- Utility function for calling relativeLink(episode, -1)
-- Returns a string
local function prevLink(episode)
    return relativeLink(episode, -1)
end
 
-- Utility function for calling relativeLink(episode, 1)
-- Returns a string
local function nextLink(episode)
    return relativeLink(episode, 1)
end
 
-- Main function when invoking the module through {{#invoke: EpisodeLinks}}
-- Takes no arguments
-- Returns readable title, previous episode link and next episode link separated with semicolons
function p.main()
    if title.namespace ~= 0 then
        return ';;'
    else
        local name = title.fullText
        return readableTitle(name) .. ';' .. prevLink(name) .. ';' .. nextLink(name)
    end
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.