Module:Main page: Difference between revisions

Jump to navigation Jump to search
another AI fix
(try fix)
(another AI fix)
 
Line 1: Line 1:
-- Module:Main_page
-- Module:Main_page
-- IMProved Main Page framework – FIXED for direct use on Main Page
-- IMProved Main Page – FINAL FIXED VERSION
-- Works on wiki.gg, Fandom, and any MediaWiki
-- Works on Main Page, Portals, and any content page


local p = {}
local p = {}


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


     -- Collect content from numbered args (content1, content2, ...)
     -- Collect content1, content2, etc.
     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 20:
     end
     end


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


Line 54: Line 46:
     end
     end


     -- Main container
     -- Grid container
     local container = html:tag('div')
     local container = html:tag('div')
         :addClass('mp-container')
         :addClass('mp-container')
Line 67: Line 59:
         })
         })


     -- Add each box
     -- Add boxes
     for _, box in ipairs(content) do
     for _, box in ipairs(content) do
         if box and box ~= '' then
         if box and box ~= '' then

Navigation menu