Moduł:Stopka portal: Różnice pomiędzy wersjami

Z Nonsensopedii, polskiej encyklopedii humoru
(międzysave)
 
M
Linia 25: Linia 25:
local name = mw.ustring.gsub(r.fulltext, 'Portal:', '')
local name = mw.ustring.gsub(r.fulltext, 'Portal:', '')
local info = portals[name]
local info = portals[name]
if info then
if info then
text = text
text = text
Linia 30: Linia 31:
.. 'style="color: ' .. info.color .. ';">[[Portal:' .. name .. '|'
.. 'style="color: ' .. info.color .. ';">[[Portal:' .. name .. '|'
.. info.letter .. ']]</span><span class="n-portal-link-text">'
.. info.letter .. ']]</span><span class="n-portal-link-text">'
.. info.text[math.random(#info.text)] .. '</span></div>'
.. ''
end
end
end
end
return text
end
end



Wersja z 16:06, 19 lut 2021

Generuje linki do portali w szablonie {{Stopka}}. Zobacz też: Moduł:Stopka.


local tools = require('Moduł:Narzędzia')
local p = {}

-- Portale dodawaj alfabetycznie.
-- Edytuj śmiało, teksty zachęcające do kliknięcia w link są losowane z podanej tu puli
local portals = {
	['Historia'] = {
		letter = 'H',
		color = '#820000',
		text = {
			"Zobacz więcej artykułów w '''[[Portal:Historia|portalu o historii]]'''."
		}
	}
}

function p.getText()
	local text = ''
	local title = mw.title.getCurrentTitle()
	local res = mw.smw.getQueryResult{ 
		'[[Zawiera artykuł::' .. title.fullText .. ']]',
		'[[Portal:+]]'
	}
	
	for _, r in ipairs(res.results) do
		local name = mw.ustring.gsub(r.fulltext, 'Portal:', '')
		local info = portals[name]
		
		if info then
			text = text 
				.. '<div class="n-portal-link"><span class="n-portal-initial link-kolor" '
				.. 'style="color: ' .. info.color .. ';">[[Portal:' .. name .. '|'
				.. info.letter .. ']]</span><span class="n-portal-link-text">'
				.. info.text[math.random(#info.text)] .. '</span></div>'
		end
	end
	
	return text
end


return p