Documentation for this module may be created at Module:NewsLanding/LatestCompanies/doc
local getArgs = require('Module:Arguments').getArgs
local cargo = mw.ext.cargo
local p = {}
function p.main(frame)
local args = getArgs(frame)
local pages = {}
local pattern = "(%d%d%d%d%-%d%d%-%d%d %d%d:%d%d:%d%d) %[%[Companies/(.-)|Companies/(.-)%]%]"
for date, title in args.companies:gmatch(pattern) do
table.insert(pages, {_pageName = 'Companies/' .. title, title = mw.text.split(title, '|')[1], date = date})
end
local hotItems = mw.html.create('div'):addClass('news-hot-items')
local container = mw.html.create('div'):addClass('news-hot'):node(mw.html.create('h3'):addClass('tc'):wikitext('Latest Company Pages')):node(hotItems)
for i, page in ipairs(pages) do
local tables = 'Logos'
local fields = '_pageName, logoAll, logoDark, logoLight, iconAll, iconLight, iconDark'
local cargoArgs = {
where = '_pageName = "' .. page._pageName .. '"'
-- where = '_pageName = "Companies/' .. string.gsub(pageTitle, '"', '""') .. '"'
}
local results = cargo.query(tables, fields, cargoArgs)
local logoDiv = mw.html.create('div')
local title = mw.html.create('div'):wikitext('[[' .. page._pageName .. '|' .. mw.ext.displaytitle.get(page._pageName) .. ']]')
local date = mw.html.create('div'):wikitext('Last edit: ' .. page.date)
-- local textDiv = mw.html.create('div'):node(title):node(date)
local newsItem = mw.html.create('div'):attr('style', 'display: flex; flex-direction: column; align-items: center; gap: 0.5rem;'):node(title):node(logoDiv):node(date)
hotItems:node(newsItem)
if #results > 0 then
local result = results[1]
if results[1].iconAll then
logoDiv:node(createLogo(result._pageName, results[1].iconAll))
elseif results[1].iconLight and results[1].iconDark then
logoDiv:node(createLogo(result._pageName, results[1].iconLight, 'light')):node(createLogo(result._pageName, results[1].iconDark, 'dark'))
elseif results[1].logoAll then
logoDiv:node(createLogo(result._pageName, results[1].logoAll))
elseif results[1].logoLight and results[1].logoDark then
logoDiv:node(createLogo(result._pageName, results[1].logoLight, 'light')):node(createLogo(result._pageName, results[1].logoDark, 'dark'))
else
local logo = results[1].iconLight or results[1].iconDark or results[1].logoLight or results[1].logoDark
logoDiv:node(createLogo(result._pageName, logo))
end
else
logoDiv:node(createLogo(page._pageName))
end
end
return container
end
function createLogo(page, url, class)
local className = class and class .. ' h-100' or 'h-100'
local logoURL = url and url or 'Team_placeholder_dark.png'
local logoContainer = mw.html.create('div')
:addClass(className)
local logo = mw.html.create('div')
:addClass('team-list-logo')
:node('[[File:' .. logoURL .. '|80x80px|link=' .. page .. ']]')
logoContainer:node(logo)
return logoContainer
end
return p