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

Module:Navigation: Difference between revisions

From PC Gaming Shelter
No edit summary
No edit summary
 
(23 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


local function renderThumb(row)
local function renderRow(label, image, target)
    local caption, img, target = row[1], row[2], row[3]
local defaultTarget = label
if not target then
if not target then
target = caption
target = defaultTarget
end
end
local html = mw.html.create()
    local html = mw.html.create()
html:tag('div')
    html:tag('div'):addClass('navthumb')
:tag('div'):attr('data-bg', img):wikitext(string.format([[%s|%s]], target, caption)):done()
        :tag('div'):addClass('navthumb-image'):attr({
:tag('div'):wikitext(string.format([[%s|%s]], target, caption)):done()
        ['data-bg'] = image,
:done()
        }):done()
     return tostring(html)
        :tag('div'):addClass('navthumb-label'):wikitext(string.format('[[%s|%s]]', target, label)):done()
    :done()
 
     return html
end
end


function p.thumbwall(frame)
function p.data(frame)
local args = frame:getParent().args
  local args = frame:getParent().args or {}
local title = args['title'] or 'Navigate'
  local title = args[1] or args['title'] or 'Navigate'
-- local thumbs = args['thumbs']
 
local thumbs = {}
  local html = mw.html.create()
for i = 2, #args do
  local card = html:tag('div'):addClass('card bg-dark thumbwall mb-3')
    if args[i] and args[i] ~= '' then
  local header = card:tag('div'):addClass('card-header'):wikitext(title):done()
        table.insert(thumbs, args[i])
  local body = card:tag('div'):addClass('card-body')
    end
 
end
local i = 1
if not thumbs then return end
while args['label' .. i] do
local label = args['label' .. i]
  -- local thumbTable = {}
local image = args['image' .. i] or ''
  --- for line in thumbs:gmatch("[^\r\n]+") do
local imageUrl = ''
        -- Split into two or three parts (target optional)
if image and image ~= '' then
  --    local img, caption, target = line:match("^%s*(.-)%s*;%s*(.-)%s*;%s*(.-)%s*$")
imageUrl = frame:preprocess(
  --    if not target then target = caption end
string.format('{{filepath:{{PAGENAME:%s}}}}', image)
  --    if img and caption then
)
  --        table.insert(thumbTable, { caption, img, target })
end
  --    end
local target = args['target' .. i] or label
  -- end
        body:node(renderRow(label, imageUrl, target))
    -- Build table of thumbs
    i = i + 1
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
end


local html = mw.html.create()
  return html
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 html
end
end


return p
return p

Latest revision as of 17:36, 18 March 2026

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

local p = {}

local function renderRow(label, image, target)
	local defaultTarget = label
	if not target then
		target = defaultTarget
	end
	
    local html = mw.html.create()
    html:tag('div'):addClass('navthumb')
        :tag('div'):addClass('navthumb-image'):attr({
        	['data-bg'] = image,
        }):done()
        :tag('div'):addClass('navthumb-label'):wikitext(string.format('[[%s|%s]]', target, label)):done()
    :done()

    return html
end

function p.data(frame)
  local args = frame:getParent().args or {}
  local title = args[1] or args['title'] or 'Navigate'
  
  local html = mw.html.create()
  local card = html:tag('div'):addClass('card bg-dark thumbwall mb-3')
  local header = card:tag('div'):addClass('card-header'):wikitext(title):done()
  local body = card:tag('div'):addClass('card-body')
  
	local i = 1
	while args['label' .. i] do
		local label = args['label' .. i]
		local image = args['image' .. i] or ''
		local imageUrl = ''
		if image and image ~= '' then
			imageUrl = frame:preprocess(
				string.format('{{filepath:{{PAGENAME:%s}}}}', image)
			)
		end
		local target = args['target' .. i] or label
        body:node(renderRow(label, imageUrl, target))
    	i = i + 1
	end

  return html
end

return p