Module:MagazineCovers

From Porn Base Central, the free encyclopedia of gay porn
Jump to navigation Jump to search

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

-- Module:MagazineCovers
local p = {}

local function renderCover(args, n)
    local cover = args['cover' .. n] or ''
    local title = args['title' .. n] or ''
    local date  = args['date' .. n]  or ''
    local desc  = args['desc' .. n]  or ''
    local name  = args['name' .. n]  or ''

    if cover == '' and title == '' and date == '' and desc == '' and name == '' then
        return ''
    end

    local card = mw.html.create('div')
        :addClass('magazine-cover')
        :css({
            display = 'inline-flex',
            ['flex-direction'] = 'column',
            width = '160px',
            ['max-width'] = '100%',
            margin = '8px 4px',
            border = '1px solid #a2a9b1',
            background = '#f8f9fa',
            ['border-radius'] = '4px',
            overflow = 'hidden',
        })

    -- Blue header
    if title ~= '' then
        card:tag('div')
            :css({
                background = '#6b85b5',
                color = 'white',
                ['font-weight'] = 'bold',
                ['text-align'] = 'center',
                padding = '6px 8px',
                ['font-size'] = '0.9em',
            })
            :wikitext(title)
    end

    local body = card:tag('div')
        :css({ padding = '8px', ['text-align'] = 'center', ['flex-grow'] = '1' })

    -- Image
    local file = cover ~= '' and cover or 'Example.jpg'
    body:wikitext('[[File:' .. file .. '|148px|link=]]')

    -- Date + Description
    if date ~= '' or desc ~= '' then
        local info = body:tag('div')
            :css({ ['margin-top'] = '6px', ['font-size'] = '0.85em', ['line-height'] = '1.35' })

        if date ~= '' then
            info:tag('div'):css('font-weight', 'bold'):wikitext(date)
        end
        if desc ~= '' then
            info:tag('div'):wikitext(desc)
        end
    end

    -- Person name (forced white underlined link)
    if name ~= '' then
        local linkText = '[[' .. name .. '|'
                     .. '<span style="color:#ffffff !important; text-decoration:underline; font-weight:bold;">'
                     .. name
                     .. '</span>]]'
        
        body:tag('div')
            :css({
                ['margin-top'] = '8px',
                padding = '5px 8px',
                ['background-color'] = '#6b85b5',
                ['text-align'] = 'center',
                ['font-size'] = '0.9em',
            })
            :wikitext(linkText)
    end

    return tostring(card)
end

function p.main(frame)
    local args = frame:getParent().args
    local container = mw.html.create('div')
        :css({
            display = 'flex',
            ['flex-wrap'] = 'wrap',
            ['justify-content'] = 'center',
            gap = '8px',
            ['max-width'] = '1000px',
            margin = '0 auto',
            padding = '10px 0'
        })

    for n = 1, 999 do
        local html = renderCover(args, n)
        if html ~= '' then
            container:wikitext(html)
        elseif n > 15 then
            break
        end
    end

    return tostring(container)
end

return p