Module:Titre sans précision

De Starfield Wiki
Révision datée du 10 janvier 2023 à 20:09 par Kharmitch (discussion | contributions) (Page créée avec « 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.simple... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Documentation[voir] [modifier] [purger]
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