Documentation for this module may be created at Module:BrandDirectory/doc
local p = {}
function p.brandDirectory(frame)
-- Use callParserFunction for SMW query
local queryResult = frame:callParserFunction{
name = '#ask',
args = {
'[[Category:CRT models]]',
'?Has brand',
format = 'array',
sep = ';;;',
propsep = ':::',
limit = '1000'
}
}
if not queryResult or queryResult == "" then
return "No CRT models found"
end
-- Parse results and count brands
local brandCounts = {}
for entry in string.gmatch(queryResult, "[^;;;]+") do
-- Each entry is "PageName:::BrandName"
local parts = mw.text.split(entry, ":::")
if parts[2] then
local brand = mw.text.trim(parts[2])
if 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 with responsive column styles
local html = mw.html.create('div')
:addClass('brand-directory')
:cssText('column-count: 4; column-gap: 2em; margin: 1.5em 0;')
for _, brand in ipairs(sortedBrands) do
local count = brandCounts[brand]
local item = html:tag('div')
:cssText('break-inside: avoid; margin-bottom: 0.5em; line-height: 1.6;')
-- Create link to brand page using wikitext
local brandPage = "CRTs by " .. brand
local linkMarkup = "[[" .. brandPage .. "|" .. brand .. "]]"
item:wikitext(linkMarkup)
item:tag('span')
:cssText('color: #72777d; font-size: 0.9em; margin-left: 0.3em;')
:wikitext('(' .. count .. ')')
end
-- Add responsive CSS
local style = mw.html.create('style')
:wikitext('@media (max-width: 1200px) { .brand-directory { column-count: 3 !important; } }')
:wikitext('@media (max-width: 800px) { .brand-directory { column-count: 2 !important; } }')
:wikitext('@media (max-width: 500px) { .brand-directory { column-count: 1 !important; } }')
return tostring(style) .. tostring(html)
end
return p