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:Infobox sort

From Wikipedia, the free encyclopedia
local p = {}

function p.asc(frame)
    local list = {}
    
	for key,value in pairs(frame.args) do
		-- Remove newlines
		local stripped = mw.text.trim((string.gsub(value, "\n", "")))
		
		if stripped:match("%S") ~= nil then
		    table.insert(list, stripped)
		end
	end
	
    table.sort( list, function (a, b)
    	local indexA = a:find("%%")
    	local indexB = b:find("%%")
    	local numberA = tonumber(a:sub(1, indexA - 1))
    	local numberB = tonumber(b:sub(1, indexB - 1))
    	return numberA < numberB 
    end )
    
    return mw.text.trim(table.concat( list, "<br>" ))
end

function p.desc(frame)
	local list = {}
	
	for key,value in pairs(frame.args) do
		-- Remove newlines
		local stripped = mw.text.trim((string.gsub(value, "\n", "")))
		
		if stripped:match("%S") ~= nil then
			table.insert(list, stripped)
		end
	end
	
    table.sort( list, function (a, b)
    	local indexA = a:find("%%")
    	local indexB = b:find("%%")
    	local numberA = tonumber(a:sub(1, indexA - 1))
    	local numberB = tonumber(b:sub(1, indexB - 1))
    	return numberA > numberB 
    end )
    
    return mw.text.trim(table.concat( list, "<br>" ))
end

return p