PC Gaming Shelter
An archive dedicated to preserving PC Gaming history and more

Module:Navigation

From PC Gaming Shelter
Revision as of 12:27, 15 March 2026 by WikiVisor (talk | contribs)

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

local p = {}

local function renderThumb(row)
    local caption, img, target = row[1], row[2], row[3]

	local html = mw.html.create()
	html:tag('div')
		:tag('div'):attr('data-bg', img):wikitext(string.format([[%s|%s]], target, caption)):done()
		:tag('div'):wikitext(string.format([[%s|%s]], target, caption)):done()
	:done()
    return tostring(html)
end

function p.thumbwall(frame)
	local args = frame:getParent().args
	local title = args['title'] or 'Navigate'
	-- local thumbs = args['thumbs']
	local thumbs = {}
	for i = 2, #args do
    	if args[i] and args[i] ~= '' then
        	table.insert(thumbs, args[i])
    	end
	end
	if not thumbs then return end
	
   -- local thumbTable = {}
   --- for line in thumbs:gmatch("[^\r\n]+") do
        -- Split into two or three parts (target optional)
   --     local img, caption, target = line:match("^%s*(.-)%s*;%s*(.-)%s*;%s*(.-)%s*$")
   --     if not target then target = caption end
   --     if img and caption then
   --         table.insert(thumbTable, { caption, img, target })
   --     end
   -- end
    -- Build table of thumbs
local thumbTable = {}
for _, line in ipairs(thumbs) do
    local img, caption, target = line:match("^%s*(.-)%s*;%s*(.-)%s*;%s*(.-)%s*$")
    if not target then target = caption end
    if img and caption then
        table.insert(thumbTable, { caption, img, target })
    end
end
	
	local wallContent = ''
	for _, row in ipairs(thumbTable) do
        wallContent = wallContent .. renderThumb(row)
	end

	local html = mw.html.create()
	html:tag('div'):addClass('card bg-dark thumbwall')
		:tag('div'):addClass('card-header'):wikitext(title):done()
		:tag('div'):addClass('card-body'):wikitext(wallContent):done()
	:done()
	
    return wallContent
end

return p