Module:LinkGridBanner
From Jules RNG Wiki
More actions
Documentation for this module may be created at Module:LinkGridBanner/doc
local p = {}
function p.render(frame)
local args = frame:getParent().args
local cards = {}
local i = 1
-- Loop to gather data
while args['title' .. i] do
table.insert(cards, {
link = args['link' .. i] or args['title' .. i],
title = args['title' .. i],
image = args['image' .. i] or 'Default.png',
body = args['body' .. i] or ''
})
i = i + 1
end
-- 1. CONTAINER STYLE
local containerStyle = {
['display'] = 'flex',
['flex-wrap'] = 'wrap',
['gap'] = '1rem',
['justify-content'] = 'center'
}
-- 2. CARD STYLE
local cardStyle = {
['flex'] = '1 1 300px',
['max-width'] = '32%',
['border'] = '1px solid var(--border-color-base)',
['border-radius'] = 'var(--border-radius-base, 12px)',
['box-shadow'] = 'var(--box-shadow-level-1)',
['overflow'] = 'hidden',
['background'] = 'var(--color-surface-1)',
['transition'] = 'transform 0.2s ease',
['box-sizing'] = 'border-box',
['display'] = 'flex', -- New: Flex column layout
['flex-direction'] = 'column' -- New: Ensures footer stays at bottom
}
-- 3. IMAGE BANNER STYLE (The Major Change)
local imageAreaStyle = {
['width'] = '100%',
['aspect-ratio'] = '16 / 9', -- Enforce 16:9 ratio
['overflow'] = 'hidden', -- Crop excess
['border-bottom'] = '1px solid var(--border-color-base)',
['position'] = 'relative',
['background'] = 'var(--color-surface-2)' -- Placeholder color
}
-- 4. TEXT STYLES
local bodyStyle = {
['padding'] = '15px',
['flex-grow'] = '1', -- New: Pushes content to fill space
['display'] = 'flex',
['flex-direction'] = 'column',
['gap'] = '8px'
}
local titleStyle = {
['font-weight'] = 'bold',
['font-size'] = '1.2em',
['color'] = 'var(--color-base)'
}
local textStyle = {
['color'] = 'var(--color-subtle)',
['font-size'] = '0.95em',
['line-height'] = '1.4',
['text-align'] = 'left' -- Keeps bullet points aligned nicely
}
-- 5. BUILD HTML
local root = mw.html.create('div'):css(containerStyle)
for _, card in ipairs(cards) do
local cardDiv = root:tag('div'):css(cardStyle)
-- Image Area (Banner)
-- We use a slightly larger image size (400px) to ensure it looks crisp
-- We add a generic class to target it with CSS if needed later
cardDiv:tag('div')
:css(imageAreaStyle)
:wikitext(string.format('[[File:%s|400px|center|link=%s|class=linkgrid-banner]]', card.image, card.link))
-- Body Area
local bodyDiv = cardDiv:tag('div'):css(bodyStyle)
-- Title
bodyDiv:tag('div')
:css(titleStyle)
:wikitext(string.format('[[%s|%s]]', card.link, card.title))
-- Description
bodyDiv:tag('div')
:css(textStyle)
:wikitext(card.body)
end
-- 6. CSS FIX FOR IMAGES
-- This tiny style block forces the Wikitext image to behave like a background cover
-- "object-fit: cover" is the magic property here.
local cssFix = mw.html.create('style')
cssFix:wikitext([[
.linkgrid-banner img {
width: 100% !important;
height: 100% !important;
object-fit: cover !important;
display: block !important;
}
/* Mobile adjustment for card width */
@media (max-width: 768px) { .citizen-card-grid > div { max-width: 100% !important; } }
]])
return tostring(cssFix) .. tostring(root)
end
return p