Module:LinkGridBanner: Difference between revisions
From Jules RNG Wiki
More actions
No edit summary |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 6: | Line 6: | ||
local i = 1 | local i = 1 | ||
while args['title' .. i] do | while args['title' .. i] do | ||
table.insert(cards, { | table.insert(cards, { | ||
link = args['link | -- CHANGE 1: We do NOT default to title anymore. | ||
-- If link is missing, it stays nil. | |||
link = args['link' .. i], | |||
title = args['title' .. i], | title = args['title' .. i], | ||
image = args['image' .. i] or 'Default.png', | image = args['image' .. i] or 'Default.png', | ||
| Line 17: | Line 18: | ||
end | end | ||
-- | -- CONTAINER STYLE | ||
local containerStyle = { | local containerStyle = { | ||
['display'] = 'flex', | ['display'] = 'flex', | ||
| Line 26: | Line 27: | ||
} | } | ||
-- | -- CARD STYLE | ||
local cardStyle = { | local cardStyle = { | ||
['flex'] = '1 1 300px', | ['flex'] = '1 1 300px', | ||
['max-width'] = '32%', | ['max-width'] = '32%', | ||
['border'] = '1px solid var(--border-color-base)', | ['border'] = '1px solid var(--border-color-base)', | ||
['border-radius'] = 'var(--border-radius-base, 12px)', | ['border-radius'] = 'var(--border-radius-base, 12px)', | ||
| Line 36: | Line 37: | ||
['background'] = 'var(--color-surface-1)', | ['background'] = 'var(--color-surface-1)', | ||
['display'] = 'flex', | ['display'] = 'flex', | ||
['flex-direction'] = 'column', | ['flex-direction'] = 'column', | ||
['transition'] = 'transform 0.2s ease', | ['transition'] = 'transform 0.2s ease', | ||
} | } | ||
-- | -- BANNER WRAPPER | ||
local imageWrapperStyle = { | local imageWrapperStyle = { | ||
['width'] = '100%', | ['width'] = '100%', | ||
['aspect-ratio'] = '16 / 9', | ['aspect-ratio'] = '16 / 9', | ||
['overflow'] = 'hidden', | ['overflow'] = 'hidden', | ||
['position'] = 'relative', | ['position'] = 'relative', | ||
| Line 50: | Line 51: | ||
} | } | ||
local root = mw.html.create('div'):css(containerStyle) | local root = mw.html.create('div'):css(containerStyle) | ||
for _, card in ipairs(cards) do | for _, card in ipairs(cards) do | ||
local cardDiv = root:tag('div'):css(cardStyle) | local cardDiv = root:tag('div') | ||
:addClass('jule-grid-card') | |||
:css(cardStyle) | |||
-- Banner Image | -- Banner Image Area | ||
local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle) | local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle) | ||
-- Text Content | -- CHANGE 2: Image Linking Logic | ||
local textDiv = cardDiv:tag('div'):css( | if card.link and card.link ~= '' then | ||
-- If link exists, link the image to it | |||
imgDiv:wikitext(string.format('[[File:%s|400px|center|link=%s|class=linkgrid-banner]]', card.image, card.link)) | |||
else | |||
-- If no link, set link= (empty) to make it unclickable | |||
imgDiv:wikitext(string.format('[[File:%s|400px|center|link=|class=linkgrid-banner]]', card.image)) | |||
end | |||
-- Text Content Area | |||
local textDiv = cardDiv:tag('div'):css({ | |||
['padding'] = '15px', | |||
['flex-grow'] = '1', | |||
['display'] = 'flex', | |||
['flex-direction'] = 'column', | |||
['gap'] = '8px' | |||
}) | |||
-- Title | -- Title | ||
textDiv:tag('div') | local titleDiv = textDiv:tag('div') | ||
:css( | :css({ | ||
:wikitext(string.format('[[%s|%s]]', card.link, card.title)) | ['font-weight'] = 'bold', | ||
['font-size'] = '1.3em', | |||
['color'] = 'var(--color-base)', | |||
['line-height'] = '1.2' | |||
}) | |||
-- CHANGE 3: Title Linking Logic | |||
if card.link and card.link ~= '' then | |||
titleDiv:wikitext(string.format('[[%s|%s]]', card.link, card.title)) | |||
else | |||
titleDiv:wikitext(card.title) | |||
end | |||
-- Body | -- Body | ||
textDiv:tag('div') | textDiv:tag('div') | ||
:css( | :css({ | ||
['color'] = 'var(--color-subtle)', | |||
['font-size'] = '0.95em', | |||
['line-height'] = '1.5' | |||
}) | |||
:wikitext(card.body) | :wikitext(card.body) | ||
end | end | ||
return tostring(root) | |||
return | |||
end | end | ||
return p | return p | ||
Latest revision as of 05:25, 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
while args['title' .. i] do
table.insert(cards, {
-- CHANGE 1: We do NOT default to title anymore.
-- If link is missing, it stays nil.
link = args['link' .. i],
title = args['title' .. i],
image = args['image' .. i] or 'Default.png',
body = args['body' .. i] or ''
})
i = i + 1
end
-- CONTAINER STYLE
local containerStyle = {
['display'] = 'flex',
['flex-wrap'] = 'wrap',
['gap'] = '1rem',
['justify-content'] = 'center',
['margin-top'] = '1rem'
}
-- 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',
}
-- BANNER 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)'
}
local root = mw.html.create('div'):css(containerStyle)
for _, card in ipairs(cards) do
local cardDiv = root:tag('div')
:addClass('jule-grid-card')
:css(cardStyle)
-- Banner Image Area
local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle)
-- CHANGE 2: Image Linking Logic
if card.link and card.link ~= '' then
-- If link exists, link the image to it
imgDiv:wikitext(string.format('[[File:%s|400px|center|link=%s|class=linkgrid-banner]]', card.image, card.link))
else
-- If no link, set link= (empty) to make it unclickable
imgDiv:wikitext(string.format('[[File:%s|400px|center|link=|class=linkgrid-banner]]', card.image))
end
-- Text Content Area
local textDiv = cardDiv:tag('div'):css({
['padding'] = '15px',
['flex-grow'] = '1',
['display'] = 'flex',
['flex-direction'] = 'column',
['gap'] = '8px'
})
-- Title
local titleDiv = textDiv:tag('div')
:css({
['font-weight'] = 'bold',
['font-size'] = '1.3em',
['color'] = 'var(--color-base)',
['line-height'] = '1.2'
})
-- CHANGE 3: Title Linking Logic
if card.link and card.link ~= '' then
titleDiv:wikitext(string.format('[[%s|%s]]', card.link, card.title))
else
titleDiv:wikitext(card.title)
end
-- Body
textDiv:tag('div')
:css({
['color'] = 'var(--color-subtle)',
['font-size'] = '0.95em',
['line-height'] = '1.5'
})
:wikitext(card.body)
end
return tostring(root)
end
return p