Module:LinkGridBanner: Difference between revisions
From Jules RNG Wiki
More actions
No edit summary |
No edit summary |
||
| Line 80: | Line 80: | ||
-- Banner Image | -- Banner Image | ||
local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle) | local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle) | ||
-- | |||
-- We apply the class 'linkgrid-banner' here, which matches the CSS we added to Common.css | |||
imgDiv:wikitext(string.format('[[File:%s|400px|center|link=%s|class=linkgrid-banner]]', card.image, card.link)) | imgDiv:wikitext(string.format('[[File:%s|400px|center|link=%s|class=linkgrid-banner]]', card.image, card.link)) | ||
| Line 97: | Line 98: | ||
end | end | ||
-- | -- Return only the HTML structure (CSS is now handled by Common.css) | ||
return tostring(root) | |||
return | |||
end | end | ||
return p | return p | ||
Revision as of 05:02, 27 January 2026
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',
['margin-top'] = '1rem'
}
-- 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)',
['display'] = 'flex',
['flex-direction'] = 'column',
['transition'] = 'transform 0.2s ease',
}
-- 3. BANNER IMAGE WRAPPER
local imageWrapperStyle = {
['width'] = '100%',
['aspect-ratio'] = '16 / 9',
['overflow'] = 'hidden',
['position'] = 'relative',
['background'] = 'var(--color-surface-2)',
['border-bottom'] = '1px solid var(--border-color-base)'
}
-- 4. TEXT CONTENT STYLE
local contentStyle = {
['padding'] = '15px',
['flex-grow'] = '1',
['display'] = 'flex',
['flex-direction'] = 'column',
['gap'] = '8px'
}
local titleStyle = {
['font-weight'] = 'bold',
['font-size'] = '1.3em',
['color'] = 'var(--color-base)',
['line-height'] = '1.2'
}
local bodyStyle = {
['color'] = 'var(--color-subtle)',
['font-size'] = '0.95em',
['line-height'] = '1.5'
}
-- 5. BUILD HTML
local root = mw.html.create('div'):css(containerStyle)
for _, card in ipairs(cards) do
local cardDiv = root:tag('div'):css(cardStyle)
-- Banner Image
local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle)
-- We apply the class 'linkgrid-banner' here, which matches the CSS we added to Common.css
imgDiv:wikitext(string.format('[[File:%s|400px|center|link=%s|class=linkgrid-banner]]', card.image, card.link))
-- Text Content
local textDiv = cardDiv:tag('div'):css(contentStyle)
-- Title
textDiv:tag('div')
:css(titleStyle)
:wikitext(string.format('[[%s|%s]]', card.link, card.title))
-- Body
textDiv:tag('div')
:css(bodyStyle)
:wikitext(card.body)
end
-- Return only the HTML structure (CSS is now handled by Common.css)
return tostring(root)
end
return p