Module:MainPageSkinSwitch

From IxWiki
Revision as of 16:28, 1 August 2024 by Heku (talk | contribs)
Jump to navigation Jump to search

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

local p = {}

function p.getMainPageContent(frame)
    local vectorContent = p.getSkinContent(frame, 'vector')
    local citizenContent = p.getSkinContent(frame, 'citizen')
    
    return '<div id="vector-content" class="skin-content">' .. vectorContent .. '</div>' ..
           '<div id="citizen-content" class="skin-content" style="display:none;">' .. citizenContent .. '</div>'
end

function p.getSkinContent(frame, skin)
    local pageName = 'Template:MainPage/' .. skin:gsub("^%l", string.upper)
    
    local page = mw.title.new(pageName)
    if not page then
        return "Error: Page '" .. pageName .. "' does not exist."
    end
    
    local content = page:getContent()
    if not content then
        return "Error: Unable to retrieve content from '" .. pageName .. "'."
    end
    
    return frame:preprocess(content)
end

function p.debugInfo(frame)
    local skin = frame.args[1] or mw.site.stats.skin or 'vector'
    return "Current skin: " .. skin
end

return p