Module:Title

From IFWiki

Documentation for this module may be created at Module:Title/doc

local p = {}
local cargo = mw.ext.cargo

function removeStopWords(title)
	local title = mw.title.getCurrentTitle().text or ''
	local stopwords = {'The ', 'the ', 'An ', 'an ', 'A ', 'a ', "L'", "l'", 'Le ', 'le ', 'La ', 'la ', 'Il ', 'il ', 'Die ', 'die '}
	
	if title ~= '' then
	    for _, stopword in ipairs(stopwords) do
	        local pattern = '^' .. stopword
	        title = string.gsub(title, pattern, '')
	    end
	end
	return title
end	

function p.defaultSort( frame )
	frame:preprocess ('{{DEFAULTSORT:' .. removeStopWords(title) .. '}}')
end

function p.sortTitle ( frame )
	return removeStopWords(title)
end

return p