Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:Resolve code category name

From Wikipedia, the free encyclopedia
local p = {}
local DEFAULT_CAT = "Category:Articles with example code"

local function category_exists(cat)
	local title = mw.title.new("Category:" .. cat)
	return title and title.exists
end

function p._resolve(lang)
	if not lang or lang == "" then
		return DEFAULT_CAT
	end

	local resolved_lang
	if lang:lower() == "cpp" then
		resolved_lang = "C++"
	else
		resolved_lang = lang:gsub("^%l", string.upper) -- First letter uppercase
	end

	local cat = "Category:Articles with example " .. resolved_lang .. " code"
	return category_exists(cat) and cat or DEFAULT_CAT
end

function p.resolve(frame)
	local arg = frame.args and frame.args[1]
	return p._resolve(arg)
end

return p