Module:Main page: Difference between revisions

try fix
m (4 revisions imported)
(try fix)
Line 1: Line 1:
-- Module:Main_page
-- Module:Main_page
-- IMProved Main Page framework for wiki.gg
-- IMProved Main Page framework – FIXED for direct use on Main Page
-- Author: wiki.gg Support Team
-- Works on wiki.gg, Fandom, and any MediaWiki
-- Version: 1.2.0


local p = {}
local p = {}


function p.main(frame)
function p.main(frame)
     local args = frame:getParent().args
     local parent = frame:getParent()
    local args = parent and parent.args or frame.args
     local content = {}
     local content = {}
     local header = args.header or ''
     local header = args.header or ''
Line 14: Line 14:
     local below = args.below or ''
     local below = args.below or ''


     -- Collect all boxes
     -- Collect content from numbered args (content1, content2, ...)
     for k, v in pairs(args) do
     for k, v in pairs(args) do
         if type(k) == 'string' and k:match('^content%d+$') then
         if type(k) == 'string' and k:match('^content%d+$') then
Line 21: Line 21:
     end
     end


     -- Fallback: use frame content if no args
     -- Fallback: if no content args, use direct wikitext between {{Main_page}} and end
    if #content == 0 and parent then
        local fullText = mw.getCurrentFrame():getParent():getTitle() == 'Main Page'
            and mw.getCurrentFrame():preprocess('{{SUBPAGENAME}}') -- not used
        local raw = parent:getContent()
        if raw then
            table.insert(content, raw)
        end
    end
 
    -- If still empty, use frame expansion (safe fallback)
     if #content == 0 then
     if #content == 0 then
         content = {frame:getParent():getContent()}
        local expanded = frame:expandTemplate{ title = 'void' } -- dummy
         content = {frame:getParent() and frame:getParent():preprocess() or ''}
     end
     end


    -- Build HTML
     local html = mw.html.create()
     local html = mw.html.create()


Line 42: Line 54:
     end
     end


     -- Main grid
     -- Main container
     local container = html:tag('div')
     local container = html:tag('div')
         :addClass('mp-container')
         :addClass('mp-container')
         :addClass(bodyclass)
         :addClass(bodyclass)
         :css('display', 'grid')
         :css({
        :css('gap', '1.5rem')
            display = 'grid',
        :css('grid-template-columns', 'repeat(auto-fit, minmax(280px, 1fr))')
            gap = '1.5rem',
        :css('margin', '1rem auto')
            ['grid-template-columns'] = 'repeat(auto-fit, minmax(280px, 1fr))',
        :css('max-width', '1600px')
            margin = '1rem auto',
        :css('padding', '0 1rem')
            ['max-width'] = '1600px',
            padding = '0 1rem'
        })


    -- Add each box
     for _, box in ipairs(content) do
     for _, box in ipairs(content) do
         container:wikitext(box)
         if box and box ~= '' then
            container:wikitext(box)
        end
     end
     end