Documentation for this module may be created at Module:BrandDirectory/doc
local p = {}
function p.brandDirectory(frame)
local smw = mw.smw
if not smw then
return "SMW not available"
end
-- Query all CRT models and their brands
local results = smw.ask({
"[[Category:CRT models]]",
"?Has brand",
limit = 1000
})
if not results then
return "No CRT models found"
end
-- Count CRTs per brand
local brandCounts = {}
for _, row in ipairs(results) do
local brand = row["Has brand"]
if brand then
-- Handle case where brand might be a table (multiple values)
if type(brand) == "table" then
brand = brand[1]
end
if brand and brand ~= "" then
brandCounts[brand] = (brandCounts[brand] or 0) + 1
end
end
end
-- Sort brands alphabetically
local sortedBrands = {}
for brand, _ in pairs(brandCounts) do
table.insert(sortedBrands, brand)
end
table.sort(sortedBrands, function(a, b)
return string.lower(a) < string.lower(b)
end)
-- Generate HTML output
local html = mw.html.create('div')
:addClass('brand-directory')
:css('column-count', '4')
:css('column-gap', '2em')
:css('margin', '1.5em 0')
for _, brand in ipairs(sortedBrands) do
local count = brandCounts[brand]
local item = html:tag('div')
:css('break-inside', 'avoid')
:css('margin-bottom', '0.5em')
:css('line-height', '1.6')
-- Create link to brand page
local brandPage = "CRTs by " .. brand
item:wikitext('[[' .. brandPage .. '|' .. brand .. ']]')
item:tag('span')
:css('color', '#72777d')
:css('font-size', '0.9em')
:css('margin-left', '0.3em')
:wikitext('(' .. count .. ')')
end
return tostring(html)
end
return p