پودمان:عنوان بدون ویژیدن

از ویکی‌پدیا، دانشنامهٔ آزاد
توضیحات پودمان[ایجاد] [پاکسازی]
local p = {}

--[[
simpletitle

This function returns the current page title without the homonymy part (the part in parenthesis).

Usage:
{{#invoke:Titre sans précision|simpletitle}}
OR
{{#invoke:Titre sans précision|simpletitle|string}}

Parameters
	string: if present this function will treat this string as the title of the page and remove
	   homonymy part if present in it. If not given the function uses the page title (without namespace)
]]
function p.simpletitle(frame)
	-- si un paramètre est indiqué, on l'utilise comme titre à traiter
	-- sinon on utilise le titre de la page actuelle
	local page = frame.args[1]
	if (page == nil or page == '') then
		page = mw.title.getCurrentTitle().text
	end

	-- rappel : faire attention, gsub() retourne une 2e valeur (le nombre de remplacements)

	-- on enlève la partie entre parenthèses
	local npage = page:gsub(' %(.+%)$', '')

	return npage
end

return p