Module:WorkersVoices
Appearance
Documentation for this module may be created at Module:WorkersVoices/doc
-- Module:WorkersVoices
-- Renders the "Worker's Voices" section with multiple tagged videos per
-- country, content warnings, curator notes, and a paired verified resource.
local p = {}
local SECTOR_LABELS = {
construction = "Construction", domestic_work = "Domestic work",
hospitality = "Hospitality", healthcare = "Healthcare",
skilled_it = "Skilled / IT", agriculture = "Agriculture",
other = "Other", unclear = "Sector unclear",
}
local SENTIMENT_LABELS = {
positive = { text = "Positive", color = "#1a7f37" },
mixed = { text = "Mixed", color = "#9a6700" },
negative = { text = "Negative", color = "#b3261e" },
}
local function escapeHtml(s)
if not s then return "" end
return mw.text.encode(s)
end
local function renderTag(text, bgColor)
return mw.html.create("span")
:addClass("voice-tag")
:cssText("background:" .. bgColor .. ";")
:wikitext(escapeHtml(text))
end
local function renderVideo(video)
local sentiment = SENTIMENT_LABELS[video.sentiment] or { text = "Unknown", color = "#888" }
local sectorLabel = SECTOR_LABELS[video.sector] or video.sector
local genderLabel = video.gender == "unclear" and "" or
(video.gender == "man" and "Man" or "Woman")
local card = mw.html.create("div")
:addClass("video-card")
:attr("data-sector", video.sector)
:attr("data-gender", video.gender)
:attr("data-sentiment", video.sentiment)
if video.contentWarning and video.contentWarning.flag then
card:tag("div")
:addClass("content-warning")
:wikitext("⚠ " .. escapeHtml(video.contentWarning.label))
end
card:tag("div")
:addClass("thumb-wrap")
:tag("div"):addClass("placeholder")
:tag("div"):addClass("play-btn"):wikitext("▶"):done()
:wikitext("YouTube embed")
:done()
local body = card:tag("div"):addClass("card-body")
local tagRow = body:tag("div"):addClass("tag-row")
tagRow:node(renderTag(sectorLabel, "#e6e6e6"))
if genderLabel ~= "" then
tagRow:node(renderTag(genderLabel, "#e6e6e6"))
end
tagRow:node(renderTag(sentiment.text, sentiment.color))
body:tag("div"):addClass("card-meta")
:wikitext("Added " .. escapeHtml(video.addedDate) .. " · ")
:tag("a")
:attr("href", video.sourceUrl)
:attr("target", "_blank")
:attr("rel", "noopener")
:wikitext("Source ↗")
if video.curatorNote and video.curatorNote ~= "" then
body:tag("div"):addClass("curator-note")
:wikitext("Why we picked this: " .. escapeHtml(video.curatorNote))
end
if video.verifiedResource and video.verifiedResource.url then
body:tag("div"):addClass("verified-resource")
:wikitext("✓ ")
:tag("a")
:attr("href", video.verifiedResource.url)
:attr("target", "_blank")
:attr("rel", "noopener")
:wikitext(escapeHtml(video.verifiedResource.label))
end
return card
end
local function renderCountry(country)
if #country.videos == 0 then
return mw.html.create("div")
:addClass("no-video")
:tag("div"):cssText("font-size:1.6em;"):wikitext("🎥"):done()
:wikitext("No account currently featured for<br><b>" ..
escapeHtml(country.flag) .. " " .. escapeHtml(country.name) .. "</b>")
end
local group = mw.html.create("div"):addClass("country-group")
group:tag("div"):addClass("country-heading")
:wikitext(escapeHtml(country.flag) .. " " .. escapeHtml(country.name))
local cards = group:tag("div"):addClass("country-video-row")
for _, video in ipairs(country.videos) do
cards:node(renderVideo(video))
end
return group
end
local function renderRegion(region)
local wrapper = mw.html.create("div")
wrapper:tag("div")
:addClass("region-title")
:cssText("color:" .. escapeHtml(region.color) .. ";")
:wikitext(escapeHtml(region.name))
local grid = wrapper:tag("div"):addClass("region-grid")
for _, country in ipairs(region.countries) do
grid:node(renderCountry(country))
end
return wrapper
end
local function renderFilterChips()
local bar = mw.html.create("div"):addClass("voice-filters")
bar:tag("span"):addClass("filter-label"):wikitext("Filter: ")
local sectors = { "construction", "domestic_work", "hospitality", "healthcare", "skilled_it", "agriculture" }
for _, sector in ipairs(sectors) do
bar:tag("button")
:addClass("filter-chip")
:attr("data-filter-type", "sector")
:attr("data-filter-value", sector)
:wikitext(SECTOR_LABELS[sector])
end
bar:tag("button")
:addClass("filter-chip")
:attr("data-filter-type", "gender")
:attr("data-filter-value", "woman")
:wikitext("Women's accounts")
bar:tag("button")
:addClass("filter-chip filter-chip-reset")
:attr("data-filter-type", "reset")
:wikitext("Clear filters")
return bar
end
function p.main(frame)
local dataPageTitle = frame.args[1] or "Data:WorkersVoices.json"
local data
if mw.loadJsonData then
data = mw.loadJsonData(dataPageTitle)
else
local content = mw.title.new(dataPageTitle):getContent()
data = mw.text.jsonDecode(content)
end
local out = mw.html.create("div"):addClass("wrap")
out:node(renderFilterChips())
for _, region in ipairs(data.regions) do
out:node(renderRegion(region))
end
return tostring(out)
end
return p